These endpoints —
POST /batch, POST /compare, POST /estimate, GET /pricing, /sessions, and /pipelines — are not wrapped by either SDK. Call them as raw REST with the same Authorization: Bearer header. See Batch, Compare, Cost estimation, Pricing, Conversation state, Pipelines, and Presets.Choose an integration
TypeScript SDK
Best for Node.js, Next.js, workers, and TypeScript services. Typed resources, streams, retries, and webhook verification are included.
Python SDK
Best for FastAPI, Flask, Django, notebooks, and background workers.
OpenAI client
Keep an existing OpenAI integration and change the base URL, API key, and model ID.
Raw REST
Use the HTTP contract directly when adding a dependency is not desirable.
Install
Create a client
https://www.ninjachat.ai/api/v1.
Next.js route handler
Next.js route handler
app/api/generate/route.ts
FastAPI route
FastAPI route
app.py
Generate a response
Use Responses for new stateless text, vision, tool, and structured-output integrations:Use Chat Completions
Use Chat Completions when your application already works with role-based messages:Stream output
Images and video
Models, usage, and traces
Search and webhooks
Run AI-assisted search through the same client:video.completed, video.failed, pipeline.completed, pipeline.failed, budget.alert, and balance.low; omit events to subscribe to all six. Store the returned signing secret immediately; it is shown once.
Handle errors
Every failed request raises a typedNinjaChatError with an HTTP status, machine-readable code, and request ID when the server produced one.
429, 500, 502, 503, and 504 responses (up to maxRetries, default 2), honor Retry-After, and attach an Idempotency-Key to billed requests before retrying so a retry can only replay, never double-bill. A 409 request_in_flight is retried only when the request carried an idempotency key; 408 is never retried. Pass maxRetries: 0 (max_retries=0) to disable retries. See Error handling and Rate limits.
Before customer traffic, complete the go-live checklist.
Package links
TypeScript on npm
@ninjachat/sdkPython on PyPI
ninjachatSource code
Browse both SDKs and release history
API quickstart
Make your first request