Skip to main content

Responses API

NUWA 兼容 OpenAI 的 Responses API,保持与官方一致的参数与返回格式。只需替换 api_keybase_url 即可在国内直连,获得多模态、推理、搜索等完整能力。

能力概览

  • Text / Image input:支持文本或图文混合输入
  • Streaming:支持流式增量返回
  • Web search & Deep research:实时搜索与深度研究
  • Reasoning 深度minimal / low / medium / highminimal 仅 gpt-5 系列支持
  • Verbosity 控制:gpt-5 系列支持 low / medium / high
  • 工具:函数调用、image_generationcode_interpretermcp、Computer Use

快速开始

与官方 OpenAI SDK 的调用方式相同,只需替换 api_keybase_url

from openai import OpenAI

client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
base_url="https://api.nuwaapi.com/v1"
)

response = client.responses.create(
model="gpt-4o-mini",
input="Hello NUWA"
)

print(response)
提示
  1. 关于模型摘要:默认关闭,可按 disabled > auto > None 配置,auto 为兼顾成本与效果的选项。
  2. gpt-5-chat 若未传入 reasoning_effort,等同于不启用推理,可获得更快响应。
  3. 深度研究模型建议使用 o1-deep-researcho1-mini-deep-research,仅支持 responses 端口。
  4. gpt-5 系列默认锁定过程一致性输出,不再使用传统 temperaturetop_p 干预。
  5. o 系列 / gpt-5 系列不再使用 max_tokens,请在 responses 端使用 max_output_tokens 控制上限。

功能示例

gpt-5 系列

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.com/v1"
)

response = client.responses.create(
model="gpt-5", # gpt-5, gpt-5-chat-latest, gpt-5-mini, gpt-5-nano
input="塔罗占卜为何有效,背后的原理和可迁移的方法是什么?Output format: Markdown",
reasoning={"effort": "minimal"},
text={"verbosity": "low"},
stream=True
)

for event in response:
print(event)

文本

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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)

图文

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.com/v1"
)

response = client.responses.create(
model="gpt-4o-mini",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "what is in this image?"},
{"type": "input_image", "image_url": "https://picsum.photos/400/300"}
]
}
]
)

print(response)

流式

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.com/v1"
)

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

for event in response:
print(event)

搜索

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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)

Deep Research

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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="o1-deep-research",
input=input_text,
tools=[
{"type": "web_search_preview"},
{"type": "code_interpreter", "container": {"type": "auto"}},
],
)

print(response.output_text)

推理

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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)

函数调用

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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",
tools=tools,
input="What is the weather like in Boston today?",
tool_choice="auto",
)

print(response)

图像生成工具

from openai import OpenAI
import base64

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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:
with open("cat_and_otter.png", "wb") as f:
f.write(base64.b64decode(image_data[0]))

代码解析器

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.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.
"""

response = 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(response.output)

MCP 调用

from openai import OpenAI

client = OpenAI(
api_key="sk-***",
base_url="https://api.nuwaapi.com/v1",
)

response = 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(response.output_text)

已知限制

  • codex-mir-latest 不支持搜索
  • Computer Use 需要配合 Playwright,参考 官方仓库
  • 截图任务耗时较长时成功率会降低
  • CAPTCHA / Cloudflare 验证可能触发循环校验