Choose an integration
TypeScript SDK
Typed clients for Node.js, Next.js and workers.
Python SDK
For Python services, notebooks and background workers.
Vercel AI SDK
Official provider for the AI SDK —
generateText, streamText, tools, and structured outputs, with the routing trace on providerMetadata.OpenAI client
Keep an existing OpenAI integration and change the base URL, API key, and model ID.
Raw REST
Call the API without an SDK.
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.
Vercel AI SDK
If your app is built on the AI SDK, use the official provider rather than a generic OpenAI-compatible shim — you keep NinjaChat’s routing policy and its routing trace.streamText, tool calling, structured outputs, and image inputs all work. Reads NINJACHAT_API_KEY from the environment, or call createNinjaChat({ apiKey }). For an ordered fallback chain, ninjachat.chain(["claude-opus-5", "gpt-5.6-sol"]) sends the models array.
Media generation, search, batch, compare, and pipelines live in @ninjachat/sdk — the AI SDK provider covers text.
Package links
TypeScript on npm
@ninjachat/sdkPython on PyPI
ninjachatAI SDK provider on npm
@ninjachat/ai-sdk-providerSource code
Browse the SDKs and release history
API quickstart
Make your first request
More capabilities
- Speech:
client.audio.speech.createreturns audio bytes (Python) or a binaryResponse(TypeScript). - Embeddings:
client.embeddings.createreturns vectors. - Reranking:
client.rerank.createreturns ranked documents. - Anthropic Messages:
client.messages.createsupports messages and streaming. - Account management: use a management credential for keys, projects and account operations.