Chat Completions
Message-based generation with native OpenAI request and response shapes.
Create a chat completion
Keep this endpoint for existing message-based integrations. Send the full conversation, including tool-call messages and tool results, on each request.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://www.cheapinference.dev/v1",
apiKey: process.env.CHEAPINFERENCE_API_KEY,
});
const result = await client.chat.completions.create({
model: "gpt-5.4-mini",
messages: [
{ role: "developer", content: "Be concise." },
{ role: "user", content: "Explain an embedding." },
],
max_completion_tokens: 1024,
});
console.log(result.choices[0]?.message.content);Messages and output
| Role | Use |
|---|---|
| system / developer | Application instructions; support varies by model |
| user | Text or supported multimodal content parts |
| assistant | Previous model messages, including tool_calls |
| tool | Result of a tool call; include its tool_call_id |
Non-streaming text is under choices[0].message.content. Tool calls live under message.tool_calls; content can be null. The endpoint supports a single completion (n=1), not multi-choice generation.
{
"id": "chatcmpl_example", "object": "chat.completion",
"choices": [{ "index": 0, "finish_reason": "stop",
"message": { "role": "assistant", "content": "Hello!" } }],
"usage": { "prompt_tokens": 12, "completion_tokens": 4, "total_tokens": 16 }
}Finish reasons
| Value | Meaning |
|---|---|
| stop | Normal completion or stop sequence |
| length | Token ceiling reached; output may be incomplete |
| tool_calls | Your application should inspect and execute tool calls |
| content_filter | Output stopped by provider filtering |
We preserve the native provider value rather than normalizing it. A reasoning model can use its entire output budget internally and return little or no visible text.
Supported options
Common OpenAI options—including temperature, top_p, penalties, seed, log probabilities, response_format, function tools, reasoning_effort, and prediction—are forwarded on compatible models. No sampling defaults are injected.
Use max_completion_tokens where supported; max_tokens is available for compatible legacy integrations. Persisted completions, audio, native web-search options, hosted tools, and n > 1 are rejected in this release.