Docs
The future will bring us hundreds of language models and dozens of providers for each. How will you choose the best?
Prioritize price or performance. OpenRouter provide front-end models that are the best for your use case.
Seamlessly integrated API. Integrate to use AI with OpenRouter's partners without efforts.
Supported Models
We currently support selecting supported models in the playground and using them on partner platforms.
OAuth PKCE
Users can connect to OpenRouter in one click using Proof Key for Code Exchange (PKCE).
- Send your user to
https://airouter.app/auth?callback_url=YOUR_SITE_URL
- You can optionally include a
code_challenge
(random password up to 256 digits) for extra security. - For maximum security, we recommend also setting
code_challenge_method
toS256
, and then settingcode_challenge
to the base64 encoding of the sha256 hash ofcode_verifier
, which you will submit in Step 2. More info in Auth0's docs.
- Once logged in, they'll be redirected back to your site with a code in the URL. Make an API call (can be frontend or backend) to exchange the code for a user-controlled API key. And that's it for PKCE!
- Look for the
code
query parameter, e.g.?code=....
fetch('https://openrouter.dev/api/v1/auth/keys', {
method: 'POST',
body: JSON.stringify({
code: $CODE_FROM_QUERY_PARAM,
code_verifier: $CODE_VERIFIER, // Only needed if you sent a code_challenge in Step 1
}),
});
- A fresh API key will be in the result under "key". Store it securely and make OpenAI-style requests:
fetch("https://openrouter.dev/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${AIROUTER_API_KEY}`,
"HTTP-Referer": `${YOUR_SITE_URL}`, // Optional, for including your app on airouter.app rankings.
"X-Title": `${YOUR_SITE_NAME}`, // Optional. Shows in rankings on airouter.app
"Content-Type": "application/json"
},
body: JSON.stringify({
"model": "gpt-3.5-turbo-0301",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
})
});
You can use JavaScript or any server-side framework.