Chat completions

Send a conversation and receive text or tool calls using the OpenAI-compatible chat endpoint.

API guide · Reviewed 11 October 2026

Endpoint and request

HTTP
POST https://formalengines.com/inference/v1/chat/completions
FieldTypeMeaning
modelstring · requiredA model ID returned by GET /models
messagesarray · requiredConversation messages, including prior turns you want the model to see
max_tokensintegerOutput budget; provider limits and reasoning behavior vary
streambooleanSet true to receive server-sent events
temperaturenumberSampling control, where supported by the model
tools / tool_choicearray / string or objectTool definitions and selection, where supported
response_formatobjectJSON or structured-output mode, where supported

Model-specific parameters are passed through where supported. OpenAI-compatible does not mean every model supports every parameter, image format, or endpoint. Use the chat-completions interface shown here; a base-URL change alone does not guarantee support for other SDK APIs such as Responses, audio, or image generation.

Supply conversation history

A multi-turn request body
{
  "model": "deepseek-v4-1-flash",
  "messages": [
    {"role": "system", "content": "You are a concise technical assistant."},
    {"role": "user", "content": "What is a database index?"},
    {"role": "assistant", "content": "A lookup structure that speeds up data retrieval."},
    {"role": "user", "content": "When would I use one?"}
  ],
  "max_tokens": 512
}

Each request supplies its own history. The gateway does not carry a conversation forward automatically. Your application or agent manages history, summarization, and tool execution.

Read the response

Read text from choices[0].message.content and tool calls from choices[0].message.tool_calls. Check finish_reason: stop normally indicates completion, length indicates the output limit, and tool_calls means your application should handle a tool request. Usage includes prompt and completion tokens when the provider reports them.

A reasoning model may expose reasoning_content separately from its answer. Do not assume an empty content field means no work occurred. Reserve enough output tokens for the answer and any model reasoning.

SDK extensions versus raw JSON

In the Python SDK, extra_body merges model-specific fields into the request. It is not a wrapper to include in raw curl JSON.

Python · optional model-specific reasoning setting
response = client.chat.completions.create(
    model="deepseek-v4-1-flash",
    messages=[{"role": "user", "content": "Say hello."}],
    max_tokens=256,
    extra_body={"reasoning": {"enabled": False}},
)

In a raw JSON request the equivalent field is "reasoning": {"enabled": false} at the top level. Support and behavior depend on the selected model; disabling reasoning is not a universal guarantee.

Need a hand? Contact support with your request ID. Keep your API key private.