POST
/
v1
/
chat
/
completions
curl -X POST "https://api.applerouter.ai/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 10,
    "total_tokens": 30
  }
}

Overview

Creates a chat completion for the provided messages. This endpoint is compatible with the OpenAI Chat Completions API and supports:
  • Text generation with conversational context
  • Streaming responses
  • Function/Tool calling
  • Vision (Image input)
  • Video generation (using veo models)
model
string
required
The model ID to use. Examples: gpt-4o, claude-3-5-sonnet, gemini-2.0-flash, veo-3.1
messages
array
required
Array of messages in the conversation
stream
boolean
Enable Streaming responses
temperature
number
Sampling temperature between 0 and 2
max_tokens
integer
Maximum number of tokens to generate
curl -X POST "https://api.applerouter.ai/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 10,
    "total_tokens": 30
  }
}

Streaming

Enable streaming to receive responses in real-time:
Python
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Vision (Image Input)

Sending images and text:
Python
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {"url": "https://example.com/image.jpg"}
                }
            ]
        }
    ]
)

Video Generation

Generate videos using the veo model:
Python
response = client.chat.completions.create(
    model="veo-3.1",
    messages=[
        {"role": "user", "content": "A cat playing piano"}
    ],
    stream=True
)

Authorizations

Authorization
string
header
required

使用 Bearer Token 认证。格式: Authorization: Bearer sk-xxxxxx

Headers

Accept
string
default:application/json
required
Authorization
string
default:sk-
required
Content-Type
string
default:application/json
required

Body

application/json
model
enum<string>
required

要使用的模型的 ID。有关哪些模型适用于聊天 API 的详细信息

Available options:
veo-3.1,
veo-3.1-fl,
veo-3.1-fast,
veo-3.1-fast-fl,
veo-3.1-landscape,
veo-3.1-landscape-fl,
veo-3.1-landscape-fast,
veo-3.1-landscape-fast-fl
messages
object[]
required
temperature
string

使用什么采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 我们通常建议改变这个或top_p但不是两者。

top_p
string

一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或temperature但不是两者。

n
string

为每个输入消息生成多少个聊天完成选项。

stream
string

如果设置,将发送部分消息增量,就像在 ChatGPT 中一样。当令牌可用时,令牌将作为纯数据服务器发送事件data: [DONE]发送,流由消息终止。

stop
string

API 将停止生成更多令牌的最多 4 个序列。

max_tokens
string

聊天完成时生成的最大令牌数。 输入标记和生成标记的总长度受模型上下文长度的限制。

presence_penalty
string

-2.0 和 2.0 之间的数字。正值会根据到目前为止是否出现在文本中来惩罚新标记,从而增加模型谈论新主题的可能性

frequency_penalty
string

-2.0 和 2.0 之间的数字。正值会根据新标记在文本中的现有频率对其进行惩罚,从而降低模型逐字重复同一行的可能性。

logit_bias
string

修改指定标记出现在完成中的可能性。 接受一个 json 对象,该对象将标记(由标记器中的标记 ID 指定)映射到从 -100 到 100 的关联偏差值。从数学上讲,偏差会在采样之前添加到模型生成的 logits 中。确切的效果因模型而异,但 -1 和 1 之间的值应该会减少或增加选择的可能性;像 -100 或 100 这样的值应该导致相关令牌的禁止或独占选择。

user
string

代表您的最终用户的唯一标识符,可以帮助 OpenAI 监控和检测滥用行为。

Response

200 - application/json
id
string
required
object
string
required
created
string
required
choices
object[]
required
usage
object
required