页面简介
OpenAI-compatible Responses API
正文摘录
Stateless OnlyThis API is stateless - each request is independent and no conversation state is persisted between requests. You must include the full conversation history in each request. Requests that set store: true or a non-null previous_response_id are rejected with a 400 error. OpenRouter’s Responses API provides OpenAI-compatible access to multiple AI models through a unified interface, designed to be a drop-in replacement for OpenAI’s Responses API. This stateless API offers enhanced capabilities including reasoning, tool calling, and web search integration, with each request being independent and no server-side state persisted. Base URL https://openrouter.ai/api/v1/responses Authentication All requests require authentication using your OpenRouter API key: TypeScriptPythoncURLGoconst response = await fetch('https://openrouter.ai/api/v1/responses', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.OPENROUTER_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'openai/gpt-4o-mini', input: 'Hello, world!', }), }); const result = await response.json(); console.log(JSON.stringify(result, null, 2)); Output{ "id": "gen-1794947580-aB47fruOzZLs4Q1yYYEw", "object": "response", "created_at": 1794947580, "model": "openai/gpt-4o-mini", "status": "completed", "completed_at": 1794947582, "output": [ { "id": "msg_tmp_twroxelw9tl", "type": "message", "role": "assistant", "status": "completed", "content": [ { "type": "output_text", "text": "Hello! How can I assist you today?", "annotations": [], "logprobs": [] } ] } ], "error": null, "incomplete_details": null, "access_programs": null, "tools": [], "tool_choice": "auto", "parallel_tool_calls": true, "max_output_tokens": null, "temperature": 1, "top_p": 1, "presence_penalty": 0, "frequency_penalty": 0, "top_logprobs": 0, "max_tool_calls": null, "metadata": {}, "background": false, "previous_response_id": null, "service_tier": "default", Core Features Basic Usage Learn the fundamentals of making requests with simple text input and handling responses. Reasoning Access advanced reasoning capabilities with configurable effort levels and encrypted reasoning chains. Tool Calling Integrate function calling with support for parallel execution and complex tool interactions. Web Search Enable web search capabilities with real-time information retrieval and citation annotations. Error Handling The API returns structured error responses: { "error": { "code": "invalid_prompt", "message": "Missing required parameter: 'model'." }, "metadata": null } For comprehensive error handling guidance, see Error Handling. Rate Limits Standard OpenRouter rate limits apply. See API Limits for details.Was this page helpful?YesNo