NouveauVoie Eco désormais sur 91 modèles : le même modèle, moins cher

Devise

Vous rechargez toujours en euros. Les autres devises sont affichées au taux du jour de la BCE. Taux de référence de la BCE

Se connecterCommencer

Documentationv1

Menu de la documentationChat completions

POST/v1/chat/completions

Chat completions

POST /v1/chat/completions: create a chat completion with any chat model, in the OpenAI format, with or without streaming.

La documentation est en anglais.

Creates a model response for a conversation, in the OpenAI Chat Completions format. Works with every model that lists /v1/chat/completions in its endpoints, whoever made it.

Base URL: https://api.nexrouting.com/v1 (also https://nexrouting.com/api/v1).

Headers

Authorizationstringrequired
Authorization: Bearer <key> (or x-api-key: <key>).
Content-Typestring
application/json. The body is read as JSON either way.

Body

modelstringrequired
Model ID, such as openai/gpt-6-astra, or openai/gpt-6-astra:eco for the Eco lane.
messagesarrayrequired
The conversation: objects with a role (system, user, assistant, tool) and content. Content can be text or an array of parts, such as images for vision models.
streamboolean
true to receive server-sent events. See Streaming.
stream_options.include_usageboolean
With stream: add a last chunk with usage.
max_completion_tokensinteger
Upper limit for output tokens. Some models use max_tokens instead.
tools, tool_choicearray, string | object
Function calling, as in the OpenAI API.
response_formatobject
JSON mode or structured output, where the model supports it.
temperature, top_p, stop, …
Sampling parameters, passed on as they are.

The gateway checks model and stream. Everything else in the body goes to the model provider unchanged, in the OpenAI format, so which other parameters work depends on the model. When the provider rejects a parameter, you get 400 invalid_request with its reason.

Example request

curl https://api.nexrouting.com/v1/chat/completions \  -H "Authorization: Bearer $NEXROUTING_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "model": "openai/gpt-6-astra",    "messages": [      {"role": "system", "content": "You are brief."},      {"role": "user", "content": "Hello"}    ]  }'

Example response

200 OK
{  "id": "chatcmpl-8f1c2e9a",  "object": "chat.completion",  "created": 1795075200,  "model": "openai/gpt-6-astra",  "choices": [    {      "index": 0,      "message": { "role": "assistant", "content": "Hello! How can I help you today?" },      "finish_reason": "stop"    }  ],  "usage": { "prompt_tokens": 9, "completion_tokens": 10, "total_tokens": 19 }}

The body is the model provider's response, with model set to the public ID. Which extra fields appear (such as system_fingerprint or prompt_tokens_details) depends on the model. With stream: true, see Streaming.

Errors

OpenAI error shape. The most common: 400 unsupported_endpoint, 401 invalid_api_key, 402 insufficient_credits, 404 model_not_found, 429 rate_limit_exceeded, 503 model_unavailable. All codes are in Errors.