> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aihubmix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Openai Responses API 支持

支持 Openai 的 Responses API 多功能接口，已经上线的功能接口如下：

* Text input：文本输入
* Image input：图文输入
* Streaming：流式调用
* Web search：搜索
* Deep research：深度研究
* Reasoning：推理深度控制，支持 4 档 (minimal / low / medium /high)，其中，minimal 仅适用于 gpt-5 系列，completion 端口中参数名为 `reasoning_effort`
* Verbosity：输出篇幅，gpt-5 系列支持 3 档 (low / medium / high)，其中，`gpt-5-chat` 仅支持 `medium`，completions 端口需要更新 openai 包来支持此参数
* Functions：函数调用
* image\_generation：绘图工具调用，图片生成部分按 `gpt-image-1` 计价
* Code Interpreter：代码解析器，与 gpt-5 搭配时，不支持 reasoning.effort 'minimal' 档位
* Remote MCP：MCP 调用
* Computer Use：自动操作

## 使用 (Python 调用)：

与官方的 OpenAI 调用方式一致，只是替换 `api_key` 和 `base_url` 进行转发。
大陆可以直连访问。

```py theme={null}
client = OpenAI(
    api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
    base_url="https://aihubmix.com/v1"
)
```

<Tip>
  1. 对于推理模型，支持通过以下参数来输出推理总结，总结细节的丰富程度为 detailed > auto > None，其中 auto 为最佳平衡。

  ```py theme={null}
  "summary": "auto" 
  ```

  2. `gpt-5-chat` 在不传入 reasoning.effort 的情况下，相当于关闭推理，适用于会话场景。
  3. 深度研究模型可选：`o3-deep-research` 和 `o4-mini-deep-research`，仅支持 `responses` 端口
  4. gpt-5 系列强调稳定推理和一致性输出，不再支持用于控制随机性的 `temprature` 和 `top_p` 参数，如果你需要更多自由度，可以尝试支持 `temprature` 的 `gpt-5-chat-latest`
  5. 推理模型（o 系列 / gpt-5 系列）已废弃 ‎`max_tokens`，请[使用 completion](https://platform.openai.com/docs/api-reference/chat/create) 的 ‎`max_completion_tokens` 或 [responses](https://platform.openai.com/docs/api-reference/responses/create) 的 `max_output_tokens` 明确限定输出 token 上限。
</Tip>

<CodeGroup>
  ```py gpt-5 系列 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  response = client.responses.create(
      model="gpt-5", # gpt-5, gpt-5-chat-latest, gpt-5-mini, gpt-5-nano
      input="Why does tarot reading work, what are the underlying principles, and what transferable methods are there? Output format: Markdown", # GPT-5 默认不使用 Markdown 格式输出，需要明确指定。
      reasoning={
          "effort": "minimal" # 推理深度 - Controls how many reasoning tokens the model generates before producing a response. value can be "minimal", "low", "medium", "high", default is "medium"
      },
      text={
          "verbosity": "low" # 输出篇幅 - Verbosity determines how many output tokens are generated. value can be "low", "medium", "high", Models before GPT-5 have used medium verbosity by default. 
      },
      stream=True
  )

  for event in response:
    print(event)
  ```

  ```py 文本 theme={null}
  from openai import OpenAI
  import os

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  response = client.responses.create(
    model="gpt-4o-mini", # codex-mini-latest 可用
    input="Tell me a three sentence bedtime story about a unicorn."
  )

  print(response)
  ```

  ```py 图文 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  response = client.responses.create(
      model="gpt-4o-mini", # codex-mini-latest 可用
      input=[
          {
              "role": "user",
              "content": [
                  { "type": "input_text", "text": "what is in this image?" },
                  {
                      "type": "input_image",
                      "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
                  }
              ]
          }
      ]
  )

  print(response)
  ```

  ```py 流式 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  response = client.responses.create(
    model="gpt-4o-mini", # codex-mini-latest 可用
    instructions="You are a helpful assistant.",
    input="Hello!",
    stream=True
  )

  for event in response:
    print(event)
  ```

  ```py 搜索 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  response = client.responses.create(
    model="gpt-4o-mini", # codex-mini-latest 不支持搜索📍
    tools=[{ "type": "web_search_preview" }],
    input="What was a positive news story from today?",
  )

  print(response)
  ```

  ```py Deep Research theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1",
      timeout=3600
  )

  input_text = """
  Research the economic impact of semaglutide on global healthcare systems.
  Do:
  - Include specific figures, trends, statistics, and measurable outcomes.
  - Prioritize reliable, up-to-date sources: peer-reviewed research, health
    organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical
    earnings reports.
  - Include inline citations and return all source metadata.

  Be analytical, avoid generalities, and ensure that each section supports
  data-backed reasoning that could inform healthcare policy or financial modeling.
  """

  response = client.responses.create(
    model="o3-deep-research", # o4-mini-deep-research
    input=input_text,
    tools=[
      {"type": "web_search_preview"},
      {"type": "code_interpreter", "container": {"type": "auto"}},
    ],
  )

  print(response.output_text)
  ```

  ```py 推理 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1/"
  )

  response = client.responses.create(
      model="o4-mini", # 支持 codex-mini-latest, o4-mini, o3-mini, o3, o1
      input="How much wood would a woodchuck chuck?",
      reasoning={
          "effort": "medium", # 支持 low, medium, high
          "summary": "auto" # 推理总结
      }
  )

  print(response)
  ```

  ```py 函数调用 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  tools = [
      {
          "type": "function",
          "name": "get_current_weather",
          "description": "Get the current weather in a given location",
          "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The city and state, e.g. San Francisco, CA",
                },
                "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
            },
            "required": ["location", "unit"],
          }
      }
  ]

  response = client.responses.create(
    model="gpt-4o-mini", # codex-mini-latest 可用
    tools=tools,
    input="What is the weather like in Boston today?",
    tool_choice="auto"
  )

  print(response)
  ```

  ```py 图片生成工具 theme={null}
  from openai import OpenAI
  import base64

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  response = client.responses.create(
      model="gpt-4.1-mini",
      input="Generate an image of gray tabby cat hugging an otter with an orange scarf",
      tools=[
          {
              "type": "image_generation",
              "background": "opaque", 
              "quality": "high",
          }
      ],
  )

  # 保存为图片文件
  image_data = [
      output.result
      for output in response.output
      if output.type == "image_generation_call"
  ]

  if image_data:
      image_base64 = image_data[0]
      with open("cat_and_otter.png", "wb") as f:
          f.write(base64.b64decode(image_base64))
  ```

  ```py 代码解析器 theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  instructions = """
  You are a personal math tutor. When asked a math question, 
  write and run code using the python tool to answer the question.
  """

  resp = client.responses.create(
      model="gpt-4.1",
      tools=[
          {
              "type": "code_interpreter",
              "container": {"type": "auto"}
          }
      ],
      instructions=instructions,
      input="I need to solve the equation 3x + 11 = 14. Can you help me?",
  )

  print(resp.output)
  ```

  ```py Remote MCP theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="AIHUBMIX_API_KEY", # 换成你在后台生成的 Key "sk-***"
      base_url="https://aihubmix.com/v1"
  )

  resp = client.responses.create(
      model="gpt-4.1",
      tools=[{
          "type": "mcp",
          "server_label": "deepwiki",
          "server_url": "https://mcp.deepwiki.com/mcp",
          "require_approval": "never",
          "allowed_tools": ["ask_question"],
      }],
      input="What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?",
  )

  print(resp.output_text)
  ```
</CodeGroup>

**注意：**

1. 最新的 \`codex-mini-latest\` 不支持搜索
2. Computer use 需要配合 Praywright 使用，建议参考[官方仓库](https://github.com/openai/openai-cua-sample-app)

已知细节问题：

* 调用用例复杂
* 截图大量，耗时久，任务成功率低
* 或触发 CAPTCHA 验证或 Cloudflare 真人验证，可能遇到无限循环

***

更新时间：2026-06-01
