Batch Requests
curl --request POST \
--url https://www.ninjachat.ai/api/v1/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"requests": [
{
"id": "chat-1",
"endpoint": "/api/v1/chat",
"body": {
"model": "gpt-5",
"messages": [
{
"role": "user",
"content": "Summarize this article about AI safety."
}
]
}
},
{
"id": "image-1",
"endpoint": "/api/v1/images",
"body": {
"model": "flux-2-klein",
"prompt": "A futuristic city skyline at sunset, concept art"
}
}
]
}
'import requests
url = "https://www.ninjachat.ai/api/v1/batch"
payload = { "requests": [
{
"id": "chat-1",
"endpoint": "/api/v1/chat",
"body": {
"model": "gpt-5",
"messages": [
{
"role": "user",
"content": "Summarize this article about AI safety."
}
]
}
},
{
"id": "image-1",
"endpoint": "/api/v1/images",
"body": {
"model": "flux-2-klein",
"prompt": "A futuristic city skyline at sunset, concept art"
}
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
requests: [
{
id: 'chat-1',
endpoint: '/api/v1/chat',
body: JSON.stringify({
model: 'gpt-5',
messages: [{role: 'user', content: 'Summarize this article about AI safety.'}]
})
},
{
id: 'image-1',
endpoint: '/api/v1/images',
body: JSON.stringify({
model: 'flux-2-klein',
prompt: 'A futuristic city skyline at sunset, concept art'
})
}
]
})
};
fetch('https://www.ninjachat.ai/api/v1/batch', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"responses": [
{
"id": "<string>",
"status": 200,
"body": {}
}
],
"cost": {
"this_request": "$0.006"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}Power Features
Batch Requests
Send multiple requests in a single HTTP call. Each item is processed independently and billed as if it were a separate request to the corresponding endpoint.
POST
/
api
/
v1
/
batch
Batch Requests
curl --request POST \
--url https://www.ninjachat.ai/api/v1/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"requests": [
{
"id": "chat-1",
"endpoint": "/api/v1/chat",
"body": {
"model": "gpt-5",
"messages": [
{
"role": "user",
"content": "Summarize this article about AI safety."
}
]
}
},
{
"id": "image-1",
"endpoint": "/api/v1/images",
"body": {
"model": "flux-2-klein",
"prompt": "A futuristic city skyline at sunset, concept art"
}
}
]
}
'import requests
url = "https://www.ninjachat.ai/api/v1/batch"
payload = { "requests": [
{
"id": "chat-1",
"endpoint": "/api/v1/chat",
"body": {
"model": "gpt-5",
"messages": [
{
"role": "user",
"content": "Summarize this article about AI safety."
}
]
}
},
{
"id": "image-1",
"endpoint": "/api/v1/images",
"body": {
"model": "flux-2-klein",
"prompt": "A futuristic city skyline at sunset, concept art"
}
}
] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
requests: [
{
id: 'chat-1',
endpoint: '/api/v1/chat',
body: JSON.stringify({
model: 'gpt-5',
messages: [{role: 'user', content: 'Summarize this article about AI safety.'}]
})
},
{
id: 'image-1',
endpoint: '/api/v1/images',
body: JSON.stringify({
model: 'flux-2-klein',
prompt: 'A futuristic city skyline at sunset, concept art'
})
}
]
})
};
fetch('https://www.ninjachat.ai/api/v1/batch', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"responses": [
{
"id": "<string>",
"status": 200,
"body": {}
}
],
"cost": {
"this_request": "$0.006"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>",
"param": "<string>"
},
"message": "<string>",
"code": "<string>",
"request_id": "<string>"
}Authorizations
API key starting with nj_sk_
Body
application/json
List of requests to execute in batch.
Required array length:
1 - 50 elementsShow child attributes
Show child attributes
⌘I