Skip to main content
POST
Create chat completion

请求体

string
必填
要使用的模型 ID(例如 gpt-4o、claude-3.5-sonnet、gemini-2.0-flash)。
array
必填
组成对话的消息列表。
boolean
默认值:false
如果为 true,返回 Server-Sent Events (SSE) 流。
number
默认值:1
采样温度,范围 0 到 2。较低的值更具确定性。
integer
要生成的最大 token 数。
number
默认值:1
核采样参数。
string | string[]
停止生成的停止序列。
number
默认值:0
token 频率惩罚(-2.0 到 2.0)。
number
默认值:0
token 存在惩罚(-2.0 到 2.0)。
array
模型可以调用的工具列表(函数调用)。
string | object
控制调用哪个工具。auto、none 或指定的工具。
object
强制指定输出格式(例如 {"type": "json_object"})。
integer
用于可复现性的确定性采样种子。

OpenModex 扩展参数

object
为此请求配置智能路由。
object
配置提示词缓存。

响应

示例

授权

Authorization
string
header
必填

API key authentication. Pass your OpenModex API key as a Bearer token in the Authorization header: Authorization: Bearer omx_sk_...

请求体

application/json

Request body for creating a chat completion.

model
string
必填

ID of the model to use.

messages
object[]
必填

A list of messages comprising the conversation so far.

stream
boolean
默认值:false

If true, partial message deltas will be sent as server-sent events.

temperature
number

Sampling temperature between 0 and 2. Higher values make output more random.

必填范围: 0 <= x <= 2
top_p
number

Nucleus sampling parameter. Only consider tokens with top_p probability mass.

n
integer

How many completions to generate for each prompt.

max_tokens
integer

The maximum number of tokens to generate in the completion.

stop

Up to 4 sequences where the API will stop generating further tokens.

frequency_penalty
number

Penalizes new tokens based on their existing frequency in the text so far.

必填范围: -2 <= x <= 2
presence_penalty
number

Penalizes new tokens based on whether they appear in the text so far.

必填范围: -2 <= x <= 2
logit_bias
object

Modify the likelihood of specified tokens appearing in the completion. Maps token IDs to bias values from -100 to 100.

tools
object[]

A list of tools the model may call.

tool_choice

Controls which tool is called by the model. Can be 'none', 'auto', 'required', or a specific tool object.

response_format
object

An object specifying the format the model must output (e.g., {"type": "json_object"}).

seed
integer

If specified, the system will attempt to sample deterministically.

user
string

A unique identifier representing your end-user, for abuse monitoring.

routing
object

Configuration for intelligent request routing.

cache
object

Configuration for response caching.

响应

Chat completion response. When stream=true, returns SSE stream of ChatCompletionChunk objects.

Response from a chat completion request.

id
string

A unique identifier for the completion.

object
enum<string>

The object type, always 'chat.completion'.

可用选项:
chat.completion
created
integer

Unix timestamp (in seconds) of when the completion was created.

model
string

The model used for the completion.

choices
object[]

A list of completion choices.

usage
object

Token usage statistics for a completion request.

system_fingerprint
string

A fingerprint representing the backend configuration.

openmodex
object

OpenModex-specific metadata included in completion responses.