Skip to main content
Use request_id to connect your application logs with NinjaChat usage and request traces.

What to record

Do not log prompts, response bodies, API keys, or webhook signing secrets by default.

Trace one request

Store the response request_id, then retrieve the normalized trace when you need routing detail.
The trace also contains the requested candidates, routing policy, excluded rails, each attempt, and the final served_by route. Use it for debugging; use aggregated usage for dashboards.

Build the operating loop

1

Log request IDs

Add request_id to the same structured log or trace span as your user action or background job.
2

Aggregate usage

Query client.usage("1d" | "7d" | "30d") for requests, spend, per-model latency, and endpoint volume.
3

Watch balance

Query client.balance() and subscribe to balance.low so a prepaid balance does not surprise production traffic.
4

Receive async events

Register signed webhooks for video and pipeline completion, failed jobs, project-budget thresholds, and low balance.
TypeScript

Health and alerting

client.health() reads the public gateway-health endpoint. It is appropriate for an external availability check, but it does not replace a real request canary. Use two checks:
  • Poll client.health() (or GET /api/v1/health without an SDK) for gateway reachability.
  • Run a small authenticated generation against your normal model policy on a slower cadence to verify auth, balance, routing, and provider execution together.
Alert on customer impact: elevated 5xx, repeated 429, latency or TTFB regression, fallback exhaustion, low balance, and webhook delivery failures. Do not page on one provider rail if fallbacks are still serving traffic successfully.

Webhook events and delivery

Each account can register up to 5 endpoints. URLs must be https on a public host. Omit events when creating an endpoint to subscribe to all six. Register in Developers → Webhooks or via POST /webhooks. Every delivery is a POST with Content-Type: application/json and this body:
Delivery is at-least-once. A non-2xx response or a 10-second timeout is retried with backoff of 1 minute, 5 minutes, 15 minutes, 1 hour, then 6 hours — 6 attempts in total — after which the delivery is marked dead. GET /webhooks/deliveries lists the last 30 days with each row’s status (pending, retrying, delivered, dead), attempts, last_error, and request_id.

Verify signed webhooks

Verify the raw request body before parsing JSON. The SDK rejects invalid signatures and timestamps older than five minutes by default.
After creating an endpoint, call client.webhooks.test(endpoint.id) and inspect client.webhooks.listDeliveries({ endpointId: endpoint.id }) before relying on live events. In Python, use client.webhooks.list_deliveries(endpoint_id=endpoint["id"]).

Request trace reference

Full trace response and routing-attempt schema.

Usage reference

Periods, model aggregation, latency, and cost fields.

Webhook reference

Endpoint creation, event types, deliveries, and test sends.

Error handling

Typed errors, retry behavior, and support correlation.