TypeScript SDK
import { NinjaChat } from "@ninjachat/sdk";
const client = new NinjaChat({ apiKey: process.env.NINJACHAT_API_KEY! });
const completion = await client.chat.completions.create({
model: "@support",
messages: [{ role: "user", content: "Help me reset my workspace." }],
});import os
from ninjachat import NinjaChat
client = NinjaChat(api_key=os.environ["NINJACHAT_API_KEY"])
completion = client.chat.completions.create(
model="@support",
messages=[{"role": "user", "content": "Help me reset my workspace."}],
)curl --request POST \
--url https://www.ninjachat.ai/api/v1/presets/{slug}/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "developer",
"content": "<string>"
}
]
}
'{
"id": "<string>",
"object": "chat.completion",
"created": 123,
"model": "<string>",
"resolved_model": "<string>",
"provider": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
"prompt_tokens_details": {
"cached_tokens": 1,
"cache_creation_tokens": 1
},
"completion_tokens_details": {
"reasoning_tokens": 1
}
},
"cost_usd": 1,
"request_id": "<string>",
"routing": {
"strategy": "balanced",
"requested_models": [
"<string>"
],
"resolved_model": "<string>",
"provider": "<string>",
"fallbacks_allowed": true,
"data_policy": "default",
"provider_attempts": [
{
"provider": "<string>",
"outcome": "served",
"attempt_index": 1
}
],
"caching": "auto",
"source": "request",
"router": {
"id": "ninja/auto",
"task": "<string>",
"classified_by": "regex",
"override": "long_context",
"reasoning": "<string>",
"candidates": [
"<string>"
],
"considered": [
{}
]
}
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}Text
Run a saved preset
Chat completion using a preset’s saved model, routing, system prompt, and parameters. Send only your messages; pass model/models to override the preset’s chain for this call. Response headers include X-Ninja-Preset and X-Ninja-Preset-Version.
POST
/
presets
/
{slug}
/
chat
/
completions
TypeScript SDK
import { NinjaChat } from "@ninjachat/sdk";
const client = new NinjaChat({ apiKey: process.env.NINJACHAT_API_KEY! });
const completion = await client.chat.completions.create({
model: "@support",
messages: [{ role: "user", content: "Help me reset my workspace." }],
});import os
from ninjachat import NinjaChat
client = NinjaChat(api_key=os.environ["NINJACHAT_API_KEY"])
completion = client.chat.completions.create(
model="@support",
messages=[{"role": "user", "content": "Help me reset my workspace."}],
)curl --request POST \
--url https://www.ninjachat.ai/api/v1/presets/{slug}/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"role": "developer",
"content": "<string>"
}
]
}
'{
"id": "<string>",
"object": "chat.completion",
"created": 123,
"model": "<string>",
"resolved_model": "<string>",
"provider": "<string>",
"choices": [
{
"index": 123,
"message": {
"role": "assistant",
"content": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
]
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 1,
"completion_tokens": 1,
"total_tokens": 1,
"prompt_tokens_details": {
"cached_tokens": 1,
"cache_creation_tokens": 1
},
"completion_tokens_details": {
"reasoning_tokens": 1
}
},
"cost_usd": 1,
"request_id": "<string>",
"routing": {
"strategy": "balanced",
"requested_models": [
"<string>"
],
"resolved_model": "<string>",
"provider": "<string>",
"fallbacks_allowed": true,
"data_policy": "default",
"provider_attempts": [
{
"provider": "<string>",
"outcome": "served",
"attempt_index": 1
}
],
"caching": "auto",
"source": "request",
"router": {
"id": "ninja/auto",
"task": "<string>",
"classified_by": "regex",
"override": "long_context",
"reasoning": "<string>",
"candidates": [
"<string>"
],
"considered": [
{}
]
}
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
}
}Authorizations
Use an API key created in the NinjaChat developer console.
Headers
Safely retry the same logical write without duplicate billing or execution.
Required string length:
1 - 255Path Parameters
Body
application/json
Required array length:
1 - 100 elements- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
Show child attributes
Show child attributes
Required string length:
1 - 160Required array length:
1 - 15 elementsRequired string length:
1 - 160Required range:
x <= 131072Required range:
0 <= x <= 2Required range:
0 <= x <= 1Required range:
-2 <= x <= 2Required range:
-2 <= x <= 2Maximum string length:
256Show child attributes
Show child attributes
- Option 1
- Option 2
- Option 3
Show child attributes
Show child attributes
Maximum array length:
32Show child attributes
Show child attributes
Available options:
none, auto, required Show child attributes
Show child attributes
Response
Chat completion or SSE stream.
Available options:
chat.completion Required string length:
1 - 160Required string length:
1 - 160Show child attributes
Show child attributes
Show child attributes
Show child attributes
Required range:
x >= 0Show child attributes
Show child attributes