Skip to content

Chat Completions API

Use the Chat Completions API to generate a response from SubQ for a list of conversation messages.

POST /v1/chat/completions

All requests must include a valid API key in the Authorization header. See Authentication for details.

Send a JSON object with the required model and messages fields. Omit optional fields unless you need to change generation behavior.

FieldTypeRequiredDescription
modelstringYesModel ID to use, such as subq-preview. See Models.
messagesarrayYesConversation messages in order. Must contain at least one message.
streambooleanNoWhen false or omitted, returns one JSON response. When true, returns server-sent events.
temperaturenumberNoSampling temperature from 0 to 2. Higher values make output more random.
max_tokensintegerNoMaximum number of tokens to generate. Must be at least 1.
top_pnumberNoNucleus sampling value from 0 to 1. Use this or temperature, not both, for most requests.
stopstring or string[]NoStop sequence or sequences where generation should stop.

This page documents the non-streaming response. For a non-streaming request, omit stream or set it to false.

Each message has a role and content.

FieldTypeRequiredDescription
rolestringYesOne of system, user, assistant, or tool.
contentstring or text part[]YesMessage text, either as a plain string or an array of text content parts.

Use system for durable instructions, user for user input, assistant for prior model responses, and tool for tool result messages already produced by your application.

The simplest content shape is a string:

{
"role": "user",
"content": "Summarize this release note."
}

You can also send text content parts:

{
"role": "user",
"content": [
{ "type": "text", "text": "Summarize this release note." }
]
}

Only text content parts are supported. Image, audio, file, and other content part types are rejected.

Use cURL for direct HTTP calls, or use the official OpenAI SDK with SubQ’s base URL.

curl --request POST \
  --url https://api.subq.ai/v1/chat/completions \
  --header 'Authorization: Bearer $SUBQ_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "subq-preview",
  "messages": [
    {
      "role": "system",
      "content": "You are concise and practical."
    },
    {
      "role": "user",
      "content": "Explain what SubQ is good for."
    }
  ],
  "temperature": 0.2,
  "max_tokens": 500
}
'

A non-streaming request returns a JSON object with the OpenAI-compatible chat completion shape.

{
"id": "chatcmpl-example",
"object": "chat.completion",
"created": 1768000000,
"model": "subq-preview",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Use SubQ for long-context chat completion requests through the SubQ API."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 31,
"completion_tokens": 27,
"total_tokens": 58
}
}
FieldTypeDescription
idstringUnique completion ID.
objectstringObject type. Non-streaming responses use chat.completion.
createdintegerUnix timestamp, in seconds, for when the completion was created.
modelstringModel ID used for the completion.
choicesarrayGenerated choices. SubQ returns at least one choice for a successful request.
usageobjectToken usage for the request.
FieldTypeDescription
indexintegerChoice index.
message.rolestringRole of the returned message, usually assistant.
message.contentstringGenerated text.
finish_reasonstringReason generation stopped. Common values include stop and length; handle unknown string values defensively.
FieldTypeDescription
prompt_tokensintegerTokens counted from the request messages.
completion_tokensintegerTokens generated in the response.
total_tokensintegerSum of prompt and completion tokens.
Authenticating...