Documentation Index
Fetch the complete documentation index at: https://narev.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Endpoint
POST /api/router/{router_id}/v1/chat/completions
Authentication
Include your Narev API key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
You can generate API keys in the Narev Cloud dashboard under Settings → API Keys.
Setup
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://narev.ai/api/router/{router_id}/v1"
)
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://narev.ai/api/router/{router_id}/v1',
})
curl -X POST https://narev.ai/api/router/{router_id}/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"
Request parameters
Required
Array of message objects, each with a role (system, user, or assistant) and content string.
Optional
When true, Narev streams the response as server-sent events (SSE).
Custom key-value pairs used by routing filters to match the request to the correct A/B test.
The Router API ignores model, temperature, top_p, max_tokens, and other generation parameters. The production variant of the matched A/B test controls these values, not the request.
Routing logic
You configure routing rules in the Narev Cloud dashboard. When a request arrives, the router evaluates the filters against the request’s messages and metadata, then forwards the request to the production variant of the matched A/B test.
Use metadata to pass contextual signals that your routing filters depend on:
response = client.chat.completions.create(
messages=[
{"role": "user", "content": "Analyze this code"}
],
extra_body={
"metadata": {
"user_tier": "premium",
"task_type": "code_review",
"complexity": "high"
}
}
)
Request examples
Basic request
response = client.chat.completions.create(
messages=[
{"role": "user", "content": "What is the capital of France?"}
]
)
With system prompt
response = client.chat.completions.create(
messages=[
{"role": "system", "content": "You are a helpful geography expert."},
{"role": "user", "content": "What is the capital of France?"}
]
)
Streaming
stream = client.chat.completions.create(
messages=[
{"role": "user", "content": "Tell me a story."}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Non-streaming
The model field reflects the model used by the matched A/B test’s production variant.
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "openai:gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Paris is the capital of France."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 13,
"completion_tokens": 7,
"total_tokens": 20
}
}
Streaming
Narev sends each token as a server-sent event (SSE) with a data: prefix:
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"openai:gpt-4","choices":[{"index":0,"delta":{"content":"Paris"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"openai:gpt-4","choices":[{"index":0,"delta":{"content":" is"},"finish_reason":null}]}
data: [DONE]
Error responses
All errors return a JSON object with an error field:
{
"error": {
"message": "Error description",
"code": "error_code"
}
}
| Status | Code | Description |
|---|
400 | bad_request | Invalid request format or parameters |
400 | no_filters_configured | Router has no filters configured |
400 | no_production_variant | Matched A/B test has no production variant |
401 | invalid_api_key | Invalid or missing API key |
402 | insufficient_credits | Insufficient credits to complete the request |
404 | router_not_found | Router ID not found |
500 | internal_error | Internal server error |