wenwen
  1. 聊天对话-OpenAI格式(/chat/completions)
wenwen
  • 聊天对话-OpenAI格式(/chat/completions)
    • 聊天
      POST
    • 流式返回
      POST
    • 结构化输出
      POST
    • 工具调用(function call)
      POST
    • 分析图片
      POST
    • 修改图片
      POST
    • 生成图片
      POST
  • 聊天对话-Anthropic格式(/messages)
    • 聊天
      POST
    • 流式返回
      POST
    • 分析图片
      POST
  • 绘图模型-OpenAI格式(/images)
    • 文生图(基础)
      POST
    • 文生图(高质量)
      POST
    • 文生图(base64)
      POST
    • 图像编辑(dall-e-2)
      POST
    • 图像编辑(gpt-image-1)
      POST
  • 绘图模型-Midjourney(/mj)
    • 文生图(Imagine)
      POST
    • 图片融合(Blend)
      POST
  • 向量化(/embeddings)
    • 文本向量化
      POST
  1. 聊天对话-OpenAI格式(/chat/completions)

结构化输出

POST
/v1/chat/completions
输出json格式结构数据
所有对话模型,都可使用此接口, 修改 model 属性为模型名
模型列表请参考问问平台:https://api.wenwen-ai.com/pricing
BASE_URL: https://api.wenwen-ai.com

请求参数

Header 参数
Authorization
string 
必需
示例值:
Bearer {YOUR_API_KEY}
Content-Type
string 
必需
示例值:
application/json
Body 参数application/json
model
string 
要使用的模型的名字
必需
messages
array [object {2}] 
必需
至今为止对话所包含的消息列表。参考右边json示例
role
string 
必需
content
string 
必需
response_format
object 
必需
type
string 
必需
json_schema
object 
必需
示例
{
           "model": "gpt-4o-2024-08-06",
           "messages": [
              {
                 "role": "system",
                 "content": "You are a helpful math tutor. Guide the user through the solution step by step."
              },
              {
                 "role": "user",
                 "content": "9.11和9.8谁大"
              }
           ],
           "response_format": {
              "type": "json_schema",
              "json_schema": {
                 "name": "math_reasoning",
                 "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
                 },
                 "strict": true
              }
           }
         }

示例代码

HTTP
Shell
JavaScript
Java
Swift
Go
PHP
Python
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
HTTP
Shell
JavaScript
Java
curl --location --request POST 'https://api.wenwen-ai.com/v1/chat/completions' \
--header 'Authorization: Bearer {YOUR_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
           "model": "gpt-4o-2024-08-06",
           "messages": [
              {
                 "role": "system",
                 "content": "You are a helpful math tutor. Guide the user through the solution step by step."
              },
              {
                 "role": "user",
                 "content": "9.11和9.8谁大"
              }
           ],
           "response_format": {
              "type": "json_schema",
              "json_schema": {
                 "name": "math_reasoning",
                 "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
                 },
                 "strict": true
              }
           }
         }'

返回响应

🟢200成功
application/json
Body
id
string 
必需
model
string 
必需
object
string 
必需
created
integer 
必需
choices
array [object {3}] 
必需
index
integer 
可选
message
object 
可选
finish_reason
string 
可选
usage
object 
必需
prompt_tokens
integer 
必需
completion_tokens
integer 
必需
total_tokens
integer 
必需
prompt_tokens_details
object 
必需
completion_tokens_details
object 
必需
input_tokens
integer 
必需
output_tokens
integer 
必需
input_tokens_details
null 
必需
示例
{
    "id": "chatcmpl-Bg48iwIDEzYI4TrkuI8W7zvE0iPsn",
    "model": "gpt-4o-2024-08-06",
    "object": "chat.completion",
    "created": 1749365388,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "{\"final_answer\":\"9.8\",\"steps\":[{\"explanation\":\"比较两个数时,可以首先比较整数部分,然后比较小数部分。这里,我们首先看整数部分。\",\"output\":\"9.11和9.8的整数部分分别是9和9。\"},{\"explanation\":\"由于整数部分相同,我们需要比较小数部分。我们来看小数部分的第一位数字,也就是十分位。\",\"output\":\"9.11的十分位是1,9.8的十分位是8。\"},{\"explanation\":\"因为8比1大,所以9.8的小数部分大于9.11的小数部分。\",\"output\":\"因此,9.8比9.11大。\"}]}"
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 97,
        "completion_tokens": 148,
        "total_tokens": 245,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "text_tokens": 0,
            "audio_tokens": 0,
            "image_tokens": 0
        },
        "completion_tokens_details": {
            "text_tokens": 0,
            "audio_tokens": 0,
            "reasoning_tokens": 0
        },
        "input_tokens": 0,
        "output_tokens": 0,
        "input_tokens_details": null
    }
}
修改于 2025-06-11 08:25:06
上一页
流式返回
下一页
工具调用(function call)
Built with