Responses API
NUWA 兼容 OpenAI 的 Responses API,保持与官方一致的参数与返回格式。只需替换 api_key 与 base_url 即可在国内直连,获得多模态、推理、搜索等完整能力。
能力概览
- Text / Image input:支持文本或图文混合输入
- Streaming:支持流式增量返回
- Web search & Deep research:实时搜索与深度研究
- Reasoning 深度:minimal / low / medium / high,
minimal仅 gpt-5 系列支持;completions端口使用reasoning_effort - Verbosity 控制:gpt-5 系列支持 low / medium / high(
gpt-5-chat仅支持 medium),completions端口需使用新版 openai 包 - 工具:函数调用、
image_generation、code_interpreter、mcp、Computer Use - 图像生成计价:按
gpt-image-1计价
快速开始
与官方 OpenAI SDK 的调用方式相同,只需替换 api_key 与 base_url:
from openai import OpenAI
client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
base_url="https://api.nuwaapi.com/v1"
)
提示:
- 关于模型摘要:默认关闭,可按
disabled > auto > None配置,auto为兼顾成本与效果的选项。 gpt-5-chat若未传入reasoning_effort,等同于不启用推理,可获得更快响应。- 深度研究模型更新为
o1-deep-research、o1-mini-deep-research,仅支持responses端口。 - gpt-5 系列默认锁定过程一致性输出,不再使用传统的
temperature、top_p干预;如需更自由的采样可尝试不传temperature的gpt-5-chat-latest。 - o 系列 / gpt-5 系列不再使用
max_tokens,请在completions端使用max_completion_tokens,或在responses端使用max_output_tokens控制上限。
代码示例
- gpt-5 系列
- 文本
- 图文
- 流式
- 搜索
- Deep Research
- 推理
- 函数调用
- 图像生成工具
- 代码解析器
- MCP调用
from openai import OpenAI
client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
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", # 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)
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", # 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-***", # 换成你在 NUWA 生成的密钥
base_url="https://api.nuwaapi.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://picsum.photos/400/300"
}
]
}
]
)
print(response)
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", # codex-mini-latest 也可用
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-***", # 换成你在 NUWA 生成的密钥
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)
from openai import OpenAI
client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
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="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)
from openai import OpenAI
client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
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-***", # 换成你在 NUWA 生成的密钥
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", # codex-mini-latest 可用
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-***", # 换成你在 NUWA 生成的密钥
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:
image_base64 = image_data[0]
with open("cat_and_otter.png", "wb") as f:
f.write(base64.b64decode(image_base64))
from openai import OpenAI
client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
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)
from openai import OpenAI
client = OpenAI(
api_key="sk-***", # 换成你在 NUWA 生成的密钥
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 验证可能触发循环校验
- 截图大图,耗时久,任务成功率低
- 难触发 CAPTCHA 验证或 Cloudflare 真人验证,可能遇到无限循环