POST
https://api.yuannengai.com
/
v1
/
responses
curl https://api.yuannengai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "model": "gpt-5",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "这张图片里有什么?"
          },
          {
            "type": "input_image",
            "image_url": "https://example.com/image.jpg"
          }
        ]
      }
    ]
  }'
{
  "code": 200,
  "data": {
    "id": "resp-9876543210",
    "object": "response",
    "created": 1677652288,
    "model": "gpt-5",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "这张图片中有一只猫和一只水獭。它们看起来正在互动,场景非常可爱和温馨。猫咪和水獭似乎相处得很融洽。"
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 156,
      "completion_tokens": 45,
      "total_tokens": 201
    }
  }
}
  • 完全兼容 OpenAI Responses API 格式
  • 支持文本和图像的多模态输入
  • 支持工具扩展:网络搜索、文件搜索、函数调用、远程 MCP
curl https://api.yuannengai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
    "model": "gpt-5",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "这张图片里有什么?"
          },
          {
            "type": "input_image",
            "image_url": "https://example.com/image.jpg"
          }
        ]
      }
    ]
  }'
{
  "code": 200,
  "data": {
    "id": "resp-9876543210",
    "object": "response",
    "created": 1677652288,
    "model": "gpt-5",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "这张图片中有一只猫和一只水獭。它们看起来正在互动,场景非常可爱和温馨。猫咪和水獭似乎相处得很融洽。"
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 156,
      "completion_tokens": 45,
      "total_tokens": 201
    }
  }
}

认证方式

Authorization
string
必填
所有接口均需要使用 Bearer Token 进行认证获取 API Key:访问 API Key 管理页面 获取您的 API Key使用时在请求头中添加:
Authorization: Bearer YOUR_API_KEY

请求参数

model
string
必填
模型名称支持的模型包括:
模型说明
gpt-5OpenAI 最新多模态模型
gpt-4o-imageGPT-4o 优化版多模态模型
gpt-4-visionGPT-4 视觉理解模型
input
array
必填
输入内容列表输入数组,每个输入项包含 rolecontent 两个字段。
temperature
number
控制输出随机性,范围 0-2
  • 较低的值(如 0.2)使输出更确定
  • 较高的值(如 1.8)使输出更随机
默认值:1.0
max_tokens
integer
生成的最大 token 数量不同模型有不同的最大值限制
stream
boolean
是否使用流式输出
  • true: 流式返回(SSE 格式)
  • false: 一次性返回完整响应
默认值:false
top_p
number
核采样参数,范围 0-1控制生成文本的多样性,建议与 temperature 二选一使用默认值:1.0
tools
array
工具列表,用于扩展模型能力支持的工具类型:
工具类型说明
web_search实时搜索互联网信息
file_search搜索已上传的文件内容
function调用自定义函数
remote_mcp连接远程模型上下文协议服务
示例:[{"type": "web_search"}]

响应参数

id
string
响应的唯一标识符
object
string
对象类型,固定为 response
created
integer
创建时间戳
model
string
实际使用的模型名称
choices
array
生成的回复列表
usage
object
Token 使用统计

使用示例

纯文本输入

{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "你好,介绍一下人工智能"
        }
      ]
    }
  ]
}

图像理解

{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "描述这张图片"
        },
        {
          "type": "input_image",
          "image_url": "https://example.com/image.jpg"
        }
      ]
    }
  ]
}

多图像分析

{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "比较这两张图片的异同"
        },
        {
          "type": "input_image",
          "image_url": "https://example.com/image1.jpg"
        },
        {
          "type": "input_image",
          "image_url": "https://example.com/image2.jpg"
        }
      ]
    }
  ]
}

Base64 编码图像

{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "分析这张图片"
        },
        {
          "type": "input_image",
          "image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
        }
      ]
    }
  ]
}

使用网络搜索工具

{
  "model": "gpt-5",
  "tools": [{ "type": "web_search" }],
  "input": "今天有什么正面的新闻?"
}

使用函数调用

{
  "model": "gpt-5",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "获取指定城市的天气信息",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string",
              "description": "城市名称,例如:北京"
            },
            "unit": {
              "type": "string",
              "enum": ["celsius", "fahrenheit"],
              "description": "温度单位"
            }
          },
          "required": ["city"]
        }
      }
    }
  ],
  "input": "北京今天天气怎么样?"
}

工具使用详解

使用网络搜索工具可以让模型访问实时互联网信息。
{
  "tools": [{ "type": "web_search" }]
}
适用场景:
  • 查询最新新闻和时事
  • 获取实时数据(股票、天气、汇率等)
  • 搜索最新的技术文档和资料
文件搜索工具允许模型在已上传的文档中搜索相关信息。
{
  "tools": [{ "type": "file_search" }]
}
适用场景:
  • 分析企业内部文档
  • 搜索技术规范和手册
  • 查询合同和法律文件

函数调用 (Function Calling)

定义自定义函数,让模型能够调用外部 API 或执行特定操作。
{
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_stock_price",
        "description": "获取股票的实时价格",
        "parameters": {
          "type": "object",
          "properties": {
            "symbol": {
              "type": "string",
              "description": "股票代码,例如:AAPL"
            }
          },
          "required": ["symbol"]
        }
      }
    }
  ]
}

远程 MCP (Remote MCP)

连接到远程模型上下文协议(MCP)服务,扩展模型能力。
{
  "tools": [
    {
      "type": "remote_mcp",
      "remote_mcp": {
        "url": "https://your-mcp-server.com/api",
        "auth_token": "your_auth_token"
      }
    }
  ]
}

注意事项

请注意以下使用限制和最佳实践。
  1. 图像 URL 要求
    • 必须是公开可访问的 URL
    • 或使用 Base64 编码的 Data URI 格式
  2. Token 计费
    • 图像会根据其分辨率消耗相应的 tokens
    • 高分辨率图像会自动调整大小以优化成本
    • 工具调用也会消耗额外的 tokens
  3. 内容顺序
    • content 数组中的元素顺序会影响模型理解
    • 建议先放置文本指令,再放置图像
  4. 多模态组合
    • 可以在一个请求中混合多个文本和图像
    • 支持多轮对话,保持上下文连贯性
  5. 工具使用限制
    • 同时使用多个工具时,模型会智能选择最合适的工具
    • 函数调用需要明确的函数定义和参数说明
  6. API 兼容性
    • 完全兼容 OpenAI Responses API 格式
    • 可无缝迁移现有 OpenAI 代码