Skip to content
English

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.

POST https://api.nexinfer.com/v1/chat/completions
Terminal window
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.

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.

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.

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.

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.

  • 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 output with Chat choices.
  • Rejected tool result: verify that tool_call_id matches the model response.

Official references: Chat Completions · Migrate to Responses · Function calling