Find slow API routes by customer and plan

Rank API endpoints by p95 latency, error rate, customer, and plan so engineering can fix performance where it affects revenue.

Updated · published

markdown for agents →

difficulty intermediate · time to value 5 minutes · execution on demand

Start from this

Show p95 and p99 API latency by route for the last 24 hours, segmented by customer_id and plan. Rank the routes hurting paid customers first.

Why this matters

Average latency hides pain. One route can be fine for free users and brutal for enterprise accounts with larger payloads. This workflow tells engineering where performance work maps to customer value.

What you get

  • p50, p95, and p99 latency by route
  • Error rate and request volume beside latency
  • Segments by customer and plan
  • A ranked fix list weighted toward paid usage

Walk through it

You

Show slow API routes for paid customers.

Agent

I’ll verify the api_request shape and rank routes by p95 latency for paid plans.

Endpoint: GET /v1/projects/:project_id/event-property-keys
Exact shape: /v1/openapi.json?path=%2Fv1%2Fprojects%2F%7Bproject_id%7D%2Fevent-property-keys&method=get
Use query parameters, not a JSON body.
Query/filter concept:
  events: ["api_request"]
Endpoint: POST /v1/projects/:project_id/analytics/query
Exact shape: /v1/openapi.json?path=%2Fv1%2Fprojects%2F%7Bproject_id%7D%2Fanalytics%2Fquery&method=post
Custom HogQL goes in the OpenAPI-defined `query` field.
Concept fields:
  query: "SELECT properties.route AS route, properties.plan AS plan, count() AS requests, quantile(0.95)(toFloat(properties.duration_ms)) AS p95_ms, quantile(0.99)(toFloat(properties.duration_ms)) AS p99_ms, avg(toInt(properties.status) >= 500) AS error_rate FROM events WHERE event = 'api_request' AND timestamp > now() - INTERVAL 24 HOUR GROUP BY route, plan ORDER BY p95_ms DESC LIMIT 30"

The output

The agent returns a table of routes with p95/p99, request volume, error rate, and which customers are affected. It should avoid recommending a route with 3 requests over one with 30,000 unless the affected customer is high value.

Setting it up

Emit one api_request event from middleware. Keep route templates stable (/v1/users/:id, not raw IDs) so aggregation works.

Variations

  • “Only show enterprise customers.”
  • “Compare p95 this week vs last week.”
  • “Find routes where retries increased after the last deploy.”

Adapt this workflow in your own agent.

Ask your agent to map the starter prompt to your saved signal map, live events, and the current HTTP API before answering.

Agentry gives coding agents production context from errors, product analytics, and deploys through one HTTP API. Fetch and read https://agentry.sh/install.md completely, then install Agentry's full first-time telemetry baseline in this repository. I authorize device-code login, saving the owner key only to ~/.agentry/credentials.json, creating one Agentry project for this repository, and read-only inspection of shipped source plus hidden CI/provider configuration. Deeply analyze the product's business logic and complete value flow before choosing telemetry. Save the complete source-backed plan and show me its exact contents and hash. Until I explicitly approve that plan or request a replacement, do not edit app/CI source, place runtime/CI credentials, commit, exercise product traffic, start proof, push, or deploy. After approval, I authorize only the reviewed targets: place the required scoped browser/server/CI credentials through the established environment or secret mechanism, preserve existing telemetry, implement and test the baseline, commit it, push that reviewed commit when the shipped CI/provider path requires it, exercise safe proof paths with test/non-customer data, and perform one deployment through the reviewed shipped CI/provider path. Ask first if proof would charge money, contact a third party, change real customer data, or require new external access. After the plan is saved, immediately before every onboarding state-changing POST, GET current onboarding state, perform only its single returned next_action, then read state again; do not batch or infer later stages. Continue until status is verified, installation_complete is true, and next_action is null. Keep all secrets, source snapshots, proof markers, and scratch files outside the repository.

+ Full access
5.5 Extra High
  1. 1. Open your repo in Codex, Claude Code, Cursor etc.
  2. 2. Paste the install prompt.
  3. 3. Your agent reads the install doc and shows you an implementation plan for approval.