curl --request POST \
--url https://api.dreamto.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-6.2-sol",
"messages": [
{
"role": "system",
"content": "你是一个简洁、专业的助手。"
},
{
"role": "user",
"content": "用三句话介绍一下量子计算。"
}
]
}
'{
"id": "<string>",
"choices": [
{
"finish_reason": "stop",
"index": 123,
"message": {
"content": "<string>",
"role": "assistant",
"refusal": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"annotations": [
{
"type": "url_citation",
"url_citation": {
"end_index": 123,
"start_index": 123,
"url": "<string>",
"title": "<string>"
}
}
],
"function_call": {
"arguments": "<string>",
"name": "<string>"
},
"audio": {
"id": "<string>",
"expires_at": 123,
"data": "<string>",
"transcript": "<string>"
}
},
"logprobs": {
"content": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
],
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
]
}
],
"refusal": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
],
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
]
}
]
}
}
],
"created": 123,
"model": "<string>",
"object": "chat.completion",
"metadata": {},
"service_tier": "auto",
"system_fingerprint": "<string>",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"text_tokens": 123,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0,
"text_tokens": 123,
"image_tokens": 123,
"cache_write_tokens": 0
}
},
"moderation": {
"input": {
"type": "moderation_results",
"model": "<string>",
"results": [
{
"type": "moderation_result",
"model": "<string>",
"flagged": true,
"categories": {},
"category_scores": {},
"category_applied_input_types": {}
}
]
},
"output": {
"type": "moderation_results",
"model": "<string>",
"results": [
{
"type": "moderation_result",
"model": "<string>",
"flagged": true,
"categories": {},
"category_scores": {},
"category_applied_input_types": {}
}
]
}
}
}{
"error": {
"code": "invalid_request",
"http_status": 400,
"message": "Invalid request.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "invalid_request_error"
}
}{
"error": {
"code": "unauthorized",
"http_status": 401,
"message": "Unauthorized.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "authentication_error"
}
}{
"error": {
"code": "insufficient_balance",
"http_status": 402,
"message": "Insufficient balance.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "insufficient_balance_error"
}
}{
"error": {
"code": "forbidden",
"http_status": 403,
"message": "Access denied.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "permission_error"
}
}{
"error": {
"code": "not_found",
"http_status": 404,
"message": "The requested model was not found.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "invalid_request_error"
}
}{
"error": {
"code": "rate_limit_exceeded",
"http_status": 429,
"message": "Rate limit exceeded. Please try again later.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "rate_limit_error"
}
}{
"error": {
"code": "api_error",
"http_status": 500,
"message": "Internal server error.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "api_error"
}
}{
"error": {
"code": "service_unavailable",
"http_status": 503,
"message": "Service temporarily unavailable. Please try again later.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "api_error"
}
}创建聊天补全
curl --request POST \
--url https://api.dreamto.ai/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "gpt-6.2-sol",
"messages": [
{
"role": "system",
"content": "你是一个简洁、专业的助手。"
},
{
"role": "user",
"content": "用三句话介绍一下量子计算。"
}
]
}
'{
"id": "<string>",
"choices": [
{
"finish_reason": "stop",
"index": 123,
"message": {
"content": "<string>",
"role": "assistant",
"refusal": "<string>",
"tool_calls": [
{
"id": "<string>",
"type": "function",
"function": {
"name": "<string>",
"arguments": "<string>"
}
}
],
"annotations": [
{
"type": "url_citation",
"url_citation": {
"end_index": 123,
"start_index": 123,
"url": "<string>",
"title": "<string>"
}
}
],
"function_call": {
"arguments": "<string>",
"name": "<string>"
},
"audio": {
"id": "<string>",
"expires_at": 123,
"data": "<string>",
"transcript": "<string>"
}
},
"logprobs": {
"content": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
],
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
]
}
],
"refusal": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
],
"top_logprobs": [
{
"token": "<string>",
"logprob": 123,
"bytes": [
123
]
}
]
}
]
}
}
],
"created": 123,
"model": "<string>",
"object": "chat.completion",
"metadata": {},
"service_tier": "auto",
"system_fingerprint": "<string>",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"text_tokens": 123,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0,
"text_tokens": 123,
"image_tokens": 123,
"cache_write_tokens": 0
}
},
"moderation": {
"input": {
"type": "moderation_results",
"model": "<string>",
"results": [
{
"type": "moderation_result",
"model": "<string>",
"flagged": true,
"categories": {},
"category_scores": {},
"category_applied_input_types": {}
}
]
},
"output": {
"type": "moderation_results",
"model": "<string>",
"results": [
{
"type": "moderation_result",
"model": "<string>",
"flagged": true,
"categories": {},
"category_scores": {},
"category_applied_input_types": {}
}
]
}
}
}{
"error": {
"code": "invalid_request",
"http_status": 400,
"message": "Invalid request.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "invalid_request_error"
}
}{
"error": {
"code": "unauthorized",
"http_status": 401,
"message": "Unauthorized.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "authentication_error"
}
}{
"error": {
"code": "insufficient_balance",
"http_status": 402,
"message": "Insufficient balance.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "insufficient_balance_error"
}
}{
"error": {
"code": "forbidden",
"http_status": 403,
"message": "Access denied.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "permission_error"
}
}{
"error": {
"code": "not_found",
"http_status": 404,
"message": "The requested model was not found.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "invalid_request_error"
}
}{
"error": {
"code": "rate_limit_exceeded",
"http_status": 429,
"message": "Rate limit exceeded. Please try again later.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "rate_limit_error"
}
}{
"error": {
"code": "api_error",
"http_status": 500,
"message": "Internal server error.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "api_error"
}
}{
"error": {
"code": "service_unavailable",
"http_status": 503,
"message": "Service temporarily unavailable. Please try again later.",
"request_id": "req_3f9a1c2b7d4e5f60718293a4",
"type": "api_error"
}
}授权
请求体
要使用的模型 ID,例如 gpt-6.2-sol。可用模型见模型介绍。
"gpt-6.2-sol"
此字段正在被 safety_identifier 和 prompt_cache_key 取代。请改用 prompt_cache_key 以保持缓存优化。终端用户的稳定标识符。用于更好地对相似请求进行分桶以提高缓存命中率,并帮助 OpenAI 检测和防止滥用。了解更多。
"user-1234"
稳定标识符,用于帮助检测应用中可能违反 OpenAI 使用政策的用户。ID 应为唯一标识每个用户的字符串,最大长度为 128 个字符。建议对用户名或电子邮件地址进行哈希处理,以避免向我们发送任何身份识别信息。了解更多。
128"safety-identifier-1234"
OpenAI 用于缓存相似请求的响应,以优化缓存命中率。取代 user 字段。了解更多。
"prompt-cache-key-1234"
已弃用。请改用 prompt_cache_options.ttl。
提示缓存的保留策略。设为 24h 可启用扩展提示缓存,使缓存的前缀保持活跃更长时间,最长 24 小时。了解更多。此字段表示最长保留策略,而 prompt_cache_options.ttl 表示最短缓存生命周期。这两个字段相互独立,互不影响。对于 gpt-5.5、gpt-5.5-pro 及未来的模型,仅支持 24h。
对于同时支持 in_memory 和 24h 的较旧模型,默认值取决于组织的数据保留策略:
- 未启用 ZDR 的组织默认为
24h。 - 已启用 ZDR 的组织在未指定
prompt_cache_retention时默认为in_memory。
in_memory, 24h 提示缓存的选项。gpt-5.6 及更新的模型支持。默认情况下,OpenAI 会自动选择一个隐式缓存断点。可以通过 prompt_cache_breakpoint 为内容块添加显式断点。每个请求最多可写入四个断点。进行缓存匹配时,OpenAI 最多考虑对话中最近的 80 个断点,不限制内容块的回溯范围。将 mode 设为 explicit 可禁用隐式断点。ttl 默认为 30m。支持的生命周期取决于所用 API。最新详情请参阅 提示缓存指南。
Show child attributes
Show child attributes
指定处理请求所用的处理类型。
- 设为 'auto' 时,请求将使用项目设置中配置的服务层级处理。除非另行配置,项目将使用 'default'。
- 设为 'default' 时,请求将按所选模型的标准价格和性能处理。
- 设为 'flex' 时,请求将使用 Flex Processing 服务层级处理。
- 要在请求级别启用 Fast 模式,请在 Responses 或 Chat Completions 中加入
service_tier=fast或service_tier=priority参数。无论请求中指定的是service_tier=fast还是priority,响应中都会显示service_tier=priority。 - 未设置时,默认行为为 'auto'。
设置了 service_tier 参数时,响应体会包含 service_tier 值,该值基于实际处理请求所用的处理模式,可能与参数中设置的值不同。
auto, default, flex, scale, priority, fast 希望模型生成的输出类型。大多数模型都能生成文本,这也是默认值:
["text"]
gpt-4o-audio-preview 模型还可用于 生成音频。要让该模型同时生成文本和音频响应,可以使用:
["text", "audio"]
text, audio 限制推理模型的推理强度。目前支持的值为 none、minimal、low、medium、high、xhigh 和 max。降低推理强度可以加快响应速度,并减少响应中用于推理的 Token。并非所有推理模型都支持每个值。各模型的支持情况请参阅 推理指南。
none, minimal, low, medium, high, xhigh, max 补全可生成的 Token 数上限,包括可见的输出 Token 和 推理 Token。
此工具在网络上搜索相关结果,用于生成响应。详见 网页搜索工具。
Show child attributes
Show child attributes
指定模型必须输出的格式的对象。
设为 { "type": "json_schema", "json_schema": {...} } 将启用结构化输出,确保模型输出与提供的 JSON Schema 匹配。详见 结构化输出指南。
设为 { "type": "json_object" } 将启用旧版 JSON 模式,确保模型生成的消息是有效的 JSON。对于支持 json_schema 的模型,推荐使用 json_schema。
- 文本
- JSON Schema
- JSON 对象
Show child attributes
Show child attributes
音频输出参数。使用 modalities: ["audio"] 请求音频输出时为必填。了解更多。
Show child attributes
Show child attributes
设为 true 时,模型响应数据将在生成过程中通过 服务器发送事件(SSE) 流式传输给客户端。更多信息请参阅 下文的流式部分;关于如何处理流式事件,请参阅 流式响应 指南。
Predicted Output 的配置。当模型响应的大部分内容已预先知道时,可以显著缩短响应时间。最常见的场景是重新生成一个大部分内容只有少量改动的文件。
Show child attributes
Show child attributes
控制模型调用哪个工具(如有)。none 表示模型不调用任何工具,而是生成一条消息。auto 表示模型可以在生成消息和调用一个或多个工具之间自行选择。required 表示模型必须调用一个或多个工具。通过 {"type": "function", "function": {"name": "my_function"}} 指定某个工具,会强制模型调用该工具。
没有工具时默认为 none;存在工具时默认为 auto。
none, auto, required 使用工具时是否启用 并行函数调用。
响应
非流式请求返回一个 Chat Completion 对象。
如果 stream 为 true,则返回服务器发送事件(text/event-stream)。成功的数据块帧包含一个符合 CreateChatCompletionStreamResponse 的 JSON Chat Completion 数据块。正常结束时,最后一帧为:
data: [DONE]
最后一帧以空行结尾。[DONE] 是字面文本,而不是 JSON 数据块,且该帧没有 event: done 字段。
如果流式开始后发生故障,某个数据帧中可能包含一个带 error 字段的 JSON 对象,而不是补全数据块。流式 schema 描述的是成功的 JSON 数据块,不包括错误帧或结束标记。中断的流可能在没有结束标记的情况下结束。
表示模型根据所提供输入返回的聊天补全响应。
指定处理请求所用的处理类型。
- 设为 'auto' 时,请求将使用项目设置中配置的服务层级处理。除非另行配置,项目将使用 'default'。
- 设为 'default' 时,请求将按所选模型的标准价格和性能处理。
- 设为 'flex' 时,请求将使用 Flex Processing 服务层级处理。
- 要在请求级别启用 Fast 模式,请在 Responses 或 Chat Completions 中加入
service_tier=fast或service_tier=priority参数。无论请求中指定的是service_tier=fast还是priority,响应中都会显示service_tier=priority。 - 未设置时,默认行为为 'auto'。
设置了 service_tier 参数时,响应体会包含 service_tier 值,该值基于实际处理请求所用的处理模式,可能与参数中设置的值不同。
auto, default, flex, scale, priority, fast 
