1. Openai
ssssapi文档
  • 模型接口
    • Openai
      • 文本生成
        POST
      • 文本生成---上下文阅读
        POST
      • 图片理解
        POST
      • 图片生成(gpt-image-1)
        POST
      • 图片编辑/edits
        POST
      • 图片编辑 / 网页版
        POST
      • 函数调用 tools
        POST
      • v1/Responses / 通用
        POST
      • 创建文本嵌入
        POST
      • 批量创建嵌入
        POST
      • 文本转语音 / TTS
        POST
      • 语音转文本 / whisper-1
        POST
      • 语音转文本 / gpt-4o-transcribe
        POST
      • 音频翻译
        POST
      • Audio接口 / 输出
        POST
      • Audio接口 / 输入
        POST
      • 内容补全接口
        POST
      • 创建内容审核
        POST
      • PDF文件分析
        POST
      • deep-research / 深度研究
        POST
      • Web search / 联网搜索
        POST
      • response_format
        POST
    • Anthropic
      • 原生接口
        • 文本生成
        • 图片理解
        • 文本生成 / 强制返回思考
        • 函数调用
        • Web search / 联网搜索
      • OpenAI兼容接口
        • 文本生成
        • 图片理解
        • 文本生成 / 强制返回思考
        • 函数调用
        • Web search / 联网搜索
    • Google
      • OpenAI兼容接口(推荐)
        • 文本生成
        • 文本生成 / 强制返回思考
        • 图片理解
        • 图片生成
        • 图片修改
        • 图片生成 / Imagen 4
        • 音频理解
        • 视频理解
        • 文本转语音 / TTS
        • 图片编辑(Nano-banana)
      • Google Gemini接口
        • 文本生成
        • 文字转语音
        • 音频转文
        • 视频转文
        • 图片理解
    • 豆包
      • doubao-seedream-4-0-250828-文生图
      • doubao-seedream-4-0-250828-图生图
      • doubao-seedream-4-0-250828-多图生图
  • 数据模型
    • 示例数据模型
      • Pet
      • Category
      • Tag
  1. Openai

response_format

POST
https://ssssapi.com/v1/chat/completions
官方结构化输出

请求参数

Header 参数

Body 参数application/json

示例
{
    "model": "gpt-4o-2024-08-06",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful math tutor."
        },
        {
            "role": "user",
            "content": "solve 8x + 31 = 2"
        }
    ],
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "name": "math_response",
            "strict": true,
            "schema": {
                "type": "object",
                "properties": {
                    "steps": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "explanation": {
                                    "type": "string"
                                },
                                "output": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "explanation",
                                "output"
                            ],
                            "additionalProperties": false
                        }
                    },
                    "final_answer": {
                        "type": "string"
                    }
                },
                "required": [
                    "steps",
                    "final_answer"
                ],
                "additionalProperties": false
            }
        }
    }
}

请求示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://ssssapi.com/v1/chat/completions' \
--header 'Accept: application/json' \
--header 'Authorization: sk-' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "gpt-4o-2024-08-06",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful math tutor."
        },
        {
            "role": "user",
            "content": "solve 8x + 31 = 2"
        }
    ],
    "response_format": {
        "type": "json_schema",
        "json_schema": {
            "name": "math_response",
            "strict": true,
            "schema": {
                "type": "object",
                "properties": {
                    "steps": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "explanation": {
                                    "type": "string"
                                },
                                "output": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "explanation",
                                "output"
                            ],
                            "additionalProperties": false
                        }
                    },
                    "final_answer": {
                        "type": "string"
                    }
                },
                "required": [
                    "steps",
                    "final_answer"
                ],
                "additionalProperties": false
            }
        }
    }
}'

返回响应

🟢200成功
application/json
Body

示例
{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "\n\nHello there, how may I assist you today?"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 9,
        "completion_tokens": 12,
        "total_tokens": 21
    }
}
修改于 2025-10-23 02:32:28
上一页
Web search / 联网搜索
下一页
文本生成
Built with