Chat Completions
Chat Completions fits existing OpenAI-compatible clients and applications built around messages and choices. For a new agent or Codex workflow, prefer the Responses API.
Endpoint
Section titled “Endpoint”POST https://api.nexinfer.com/v1/chat/completionsMinimal request
Section titled “Minimal request”curl https://api.nexinfer.com/v1/chat/completions \ -H "Authorization: Bearer $NEXINFER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "YOUR_MODEL_ID", "messages": [ {"role": "system", "content": "Answer concisely."}, {"role": "user", "content": "Reply with OK."} ] }'Text output is commonly available at choices[0].message.content. Multimodal content, reasoning fields, and usage shapes may vary by model.
Common fields
Section titled “Common fields”| Field | Purpose |
|---|---|
model |
A model ID allowed by the key |
messages |
Conversation messages ordered by role |
stream |
Enable incremental SSE output |
tools / tool_choice |
Declare tools and selection behavior |
temperature |
Sampling control; some models restrict it |
max_tokens |
Compatibility output limit; support varies by model |
NexInfer preserves the original system, messages, tools, tool_choice, temperature, and max_tokens values. A preserved field is not a promise that every model accepts it.
Streaming
Section titled “Streaming”Set "stream": true to receive SSE deltas. Handle choices[].delta, finish reasons, and the stream terminator. If the connection drops, record the request ID and cap automatic retries.
Tool calls
Section titled “Tool calls”The model may return tool_calls in an assistant message. Execute the tool, then send its result with role: "tool" and the matching tool_call_id before continuing.
Validate all generated arguments. Require confirmation or idempotency controls for operations with side effects.
When to move to Responses
Section titled “When to move to Responses”Prefer Responses when you are:
- building a Codex or new agent workflow;
- using typed streaming events and the Item model;
- continuing a conversation with
previous_response_id; - adopting OpenAI capabilities through its primary new interface.
If an existing SDK only understands messages and choices, or your application already depends on this stable shape, you can keep Chat Completions. Migration is not required for its own sake.
Troubleshooting
Section titled “Troubleshooting”400: check message roles, content shapes, and model-supported parameters.401/403: check the bearer key, model permission, and group.- Wrong response shape: do not mix Responses
outputwith Chatchoices. - Rejected tool result: verify that
tool_call_idmatches the model response.
Official references: Chat Completions · Migrate to Responses · Function calling