OpenResponses API with 资产生成
资产生成 supports the OpenResponses API specification, an open standard for AI model interactions. OpenResponses provides a unified interface across providers with built-in support for streaming, tool calling, reasoning, and multi-modal inputs.
The OpenResponses-compatible API is available at:
https://ai-gateway.vercel.sh/v1
The OpenResponses API supports the same authentication methods as the main 资产生成:
- API key: Use your 资产生成 API key with the
Authorization: Bearer <token>header - OIDC token: Use your Vercel OIDC token with the
Authorization: Bearer <token>header
You only need to use one of these forms of authentication. If an API key is specified it will take precedence over any OIDC token, even if the API key is invalid.
The OpenResponses API supports the following features:
- Text generation - Generate text responses from prompts
- Streaming - Stream tokens as they're generated
- Tool calling - Define tools the model can call
- Structured outputs - Constrain the response to a JSON schema
- Reasoning - Control how much a model thinks before answering
- Images - Send images for analysis
- Advanced - Configure model fallbacks and provider-specific settings
Generate a text response:
const apiKey = process.env.AI_GATEWAY_API_KEY;
const response = await fetch('https://ai-gateway.vercel.sh/v1/responses', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: 'anthropic/claude-opus-5',
input: [
{
type: 'message',
role: 'user',
content: 'What is the capital of France?',
},
],
}),
});
const result = await response.json();
const message = result.output.find((item: { type: string }) => item.type === 'message');
for (const block of message.content) {
if (block.type === 'output_text') console.log(block.text);
}import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv('AI_GATEWAY_API_KEY'),
base_url='https://ai-gateway.vercel.sh/v1',
)
response = client.responses.create(
model='anthropic/claude-opus-5',
input=[
{
'type': 'message',
'role': 'user',
'content': 'What is the capital of France?',
},
],
)
message = next(item for item in response.output if item.type == 'message')
for block in message.content:
if block.type == "output_text":
print(block.text)curl -X POST "https://ai-gateway.vercel.sh/v1/responses" \
-H "Authorization: Bearer $AI_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-opus-5",
"input": [
{
"type": "message",
"role": "user",
"content": "What is the capital of France?"
}
]
}'model(string): The model ID inprovider/modelformat (e.g.,openai/gpt-6-astra,anthropic/claude-opus-5)input(array): Array of message objects containingtype,role, andcontentfields
stream(boolean): Stream the response. Defaults tofalsetemperature(number): Controls randomness. Range: 0-2top_p(number): Nucleus sampling. Range: 0-1max_output_tokens(integer): Maximum tokens to generatetools(array): Tool definitions for function callingtool_choice(string): Tool selection mode:auto,required, ornonereasoning(object): Reasoning configuration witheffortlevelproviderOptions(object): Provider-specific options for gateway configuration
This example shows how to combine multiple parameters to control the model's behavior, set up fallbacks, and enable reasoning.
const response = await fetch('https://ai-gateway.vercel.sh/v1/responses', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.AI_GATEWAY_API_KEY}`,
},
body: JSON.stringify({
model: 'anthropic/claude-opus-5', // provider/model format
input: [
{
type: 'message',
role: 'user',
content: 'Explain neural networks.',
},
],
stream: true, // stream tokens as generated
max_output_tokens: 500, // limit response length
reasoning: {
effort: 'medium', // reasoning depth
},
providerOptions: {
gateway: {
models: ['anthropic/claude-opus-5', 'openai/gpt-6-astra'], // fallbacks
},
},
}),
});The API returns standard HTTP status codes and error responses.
400 Bad Request- Invalid request parameters401 Unauthorized- Invalid or missing authentication403 Forbidden- Insufficient permissions404 Not Found- Model or endpoint not found429 Too Many Requests- Rate limit exceeded500 Internal Server Error- Server error
When an error occurs, the API returns a JSON object with details about what went wrong.
{
"error": {
"message": "Invalid request: missing required parameter 'model'",
"type": "invalid_request_error",
"param": "model",
"code": "missing_parameter"
}
}Was this helpful?