页面简介
One API key for text, image generation, video generation, text-to-speech, and speech-to-text across 700+ models from 100+ providers, with typed SDKs.
正文摘录
Developer PlatformBuild with every model. From one platform.One OpenAI-compatible API, typed SDKs in three languages, an agent framework, and an MCP server — backed by 700+ models across 100+ providers with automatic fallback.Get an API keyRead the docsEverything you need to shipOne platform, one API key. Start with a single request and grow into a production agent without changing providers. That key covers text, image generation, video generation, text-to-speech, and speech-to-text models, documented in the multimodal guides.APIOne OpenAI-compatible endpoint for 700+ models across 100+ providers, with automatic fallback when a provider fails.https://openrouter.ai/api/v1Client SDKsThe same typed client in TypeScript, Python, and Go — streaming, tools, and structured output behave identically in every language.TypeScriptPythonGo Betanpm i @openrouter/sdkAgent SDKType-safe tools, multi-turn loops, streaming, and stop conditions. Build production agents that route across every provider.TypeScriptPython BetaGo Betanpm i @openrouter/agentTerraform ProviderManage OpenRouter as infrastructure-as-code with repeatable, reviewable configuration for your platform.source = "OpenRouterTeam/openrouter"MCP ServerGive any Model Context Protocol client — Claude Code, Cursor, or your own — access to all 700+ models.https://mcp.openrouter.ai/mcpCookbookWorking recipes for agent harnesses, human-in-the-loop tools, evals, cost control, and image generation.A few lines to productionSwap the model string to change providers. Nothing else about your code has to change.Call a modelStream tokensCall a toolTypeScriptPythonimport { OpenRouter } from '@openrouter/sdk'; const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY, }); const response = await client.chat.send({ model: 'anthropic/claude-sonnet-4', messages: [ { role: 'user', content: 'Explain quantum computing in simple terms.' }, ], }); console.log(response.choices[0].message.content);from openrouter import OpenRouter import os with OpenRouter( api_key=os.getenv("OPENROUTER_API_KEY") ) as client: response = client.chat.send( model="anthropic/claude-sonnet-4", messages=[ {"role": "user", "content": "Explain quantum computing in simple terms."} ] ) print(response.choices[0].message.content)TypeScriptPythonimport { OpenRouter } from '@openrouter/sdk'; const client = new OpenRouter(); const stream = await client.chat.send({ model: 'openai/gpt-4o', messages: [{ role: 'user', content: 'Write a short story about a robot.' }], stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? ''); }from openrouter import OpenRouter import os with OpenRouter( api_key=os.getenv("OPENROUTER_API_KEY") ) as client: stream = client.chat.send( model="openai/gpt-4o", messages=[ {"role": "user", "content": "Write a short story about a robot."} ], stream=True ) for event in stream: content = event.choices[0].delta.content if event.choices else None if content: print(content, end="", flush=True)TypeScriptPython// Multi-turn tool loops live in the Agent SDK: npm i @openrouter/agent import { OpenRouter, tool, stepCountIs } from '@openrouter/agent'; import { z } from '@openrouter-monorepo/lib-zod'; const openrouter = new OpenRouter(); const weatherTool = tool({ name: 'get_weather', description: 'Get the weather for a location', inputSchema: z.object({ location: z.string(), }), execute: async ({ location }) => { return { temperature: 72, condition: 'sunny' }; }, }); const result = openrouter.callModel({ model: 'openai/gpt-4o', input: 'What should I wear in San Francisco today?', tools: [weatherTool], stopWhen: stepCountIs(5), }); console.log(await result.getText());# The Client SDK returns tool calls for you to dispatch yourself. from openrouter import OpenRouter import os with OpenRouter( api_key=os.getenv("OPENROUTER_API_KEY") ) as client: response = client.chat.send( model="openai/gpt-4o", messages=[ {"role": "user", "content": "What should I wear in San Francisco today?"} ], tools=[{ "type": "function", "function": { "name": "get_weather", "description": "Get the weather for a location", "parameters": { "type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"], }, }, }] ) print(response.choices[0].message.tool_calls)Live in three stepsMost teams are through their first successful request in under five minutes.1Get an API keyCreate a key from your dashboard. No subscription and no card required to start.2Point your client at OpenRouterAlready using the OpenAI SDK? Change the base URL and your key. Everything else stays put.3Pick any modelUse an author/slug string. Add fallbacks so a provider outage never becomes your outage.Read the full quickstartYour first requestcurl https://openrouter.ai/api/v1/chat/completions \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "models": [ "anthropic/claude-sonnet-4", "openai/gpt-4o", "google/gemini-2.5-pro" ], "messages": [ { "role": "user", "content": "Hello!" } ] }'Start building todayFree to get started. No subscription, no card required.Get an API keyRead the docs