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.
Die Dokumentation ist auf Englisch.
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
AuthorizationstringrequiredAuthorization: Bearer <key>(orx-api-key: <key>).Content-Typestringapplication/json. The body is read as JSON either way.
Body
modelstringrequired- Model ID, such as
openai/gpt-6-astra, oropenai/gpt-6-astra:ecofor the Eco lane. messagesarrayrequired- The conversation: objects with a
role(system,user,assistant,tool) andcontent. Content can be text or an array of parts, such as images for vision models. streambooleantrueto receive server-sent events. See Streaming.stream_options.include_usageboolean- With
stream: add a last chunk withusage. max_completion_tokensinteger- Upper limit for output tokens. Some models use
max_tokensinstead. 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
{ "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.