Quick Start Guide

Get up and running with OpenRouterX API in minutes. Our API is fully compatible with OpenAI's interface.

1

Get your API key

Sign up and create an API key from your dashboard.

Environment Variable
export OPENROUTERX_API_KEY="your_api_key_here"
2

Install the client

Use our official Python client or any OpenAI-compatible library.

pip install
pip install openai  # OpenAI client works with our API
3

Make your first request

Send a chat completion request to Claude Code or Gemini Pro.

Python
import openai

client = openai.OpenAI(
    api_key="your_api_key_here",
    base_url="https://api.openrouterx.com/v1"
)

response = client.chat.completions.create(
    model="claude-code",
    messages=[
        {"role": "user", "content": "Write a Python function to calculate fibonacci"}
    ]
)

print(response.choices[0].message.content)

Authentication

OpenRouterX uses API keys for authentication. Include your API key in the Authorization header.

HTTP Header
Authorization: Bearer your_api_key_here
Keep your API key secure

Never expose your API key in client-side code. Use environment variables or secure key management systems.

Making Requests

All API requests should be made to https://api.openrouterx.com/v1 with proper authentication.

Base URL

https://api.openrouterx.com/v1

Request Headers

Required Headers
Authorization: Bearer your_api_key_here
Content-Type: application/json

Chat Completions

Create a chat completion using Claude Code or Gemini Pro models.

Endpoint

POST https://api.openrouterx.com/v1/chat/completions

Request Body

JSON
{
  "model": "claude-code",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful coding assistant."
    },
    {
      "role": "user", 
      "content": "Write a Python function to reverse a string"
    }
  ],
  "max_tokens": 1000,
  "temperature": 0.7
}

Parameters

model
string
Model to use: "claude-code" or "gemini-pro"
messages
array
Array of message objects with role and content
max_tokens
integer
Maximum tokens to generate (optional)
temperature
number
Sampling temperature 0-2 (optional, default: 1)

Available Models

OpenRouterX provides access to premium AI models optimized for different use cases.

Claude Code

claude-code
Context Window 200K tokens
Input Price $0.0015/1K tokens
Output Price $0.0075/1K tokens
Best For Code generation, debugging

Gemini Pro

gemini-pro
Context Window 1M tokens
Input Price $0.00125/1K tokens
Output Price $0.00375/1K tokens
Best For Reasoning, analysis, creative tasks

Python Examples

Basic Chat Completion

Python
import openai
import os

client = openai.OpenAI(
    api_key=os.getenv("OPENROUTERX_API_KEY"),
    base_url="https://api.openrouterx.com/v1"
)

# Using Claude Code for programming tasks
response = client.chat.completions.create(
    model="claude-code",
    messages=[
        {
            "role": "system", 
            "content": "You are an expert Python developer."
        },
        {
            "role": "user", 
            "content": "Create a class for a binary search tree with insert and search methods."
        }
    ],
    max_tokens=1500,
    temperature=0.2
)

print(response.choices[0].message.content)

Streaming Response

Python - Streaming
stream = client.chat.completions.create(
    model="gemini-pro",
    messages=[
        {"role": "user", "content": "Explain quantum computing"}
    ],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

JavaScript Examples

Node.js
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.OPENROUTERX_API_KEY,
  baseURL: 'https://api.openrouterx.com/v1'
});

async function generateCode() {
  const response = await client.chat.completions.create({
    model: 'claude-code',
    messages: [
      {
        role: 'user',
        content: 'Write a JavaScript function to debounce user input'
      }
    ],
    max_tokens: 1000
  });
  
  console.log(response.choices[0].message.content);
}

generateCode();

cURL Examples

cURL
curl -X POST https://api.openrouterx.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTERX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-code",
    "messages": [
      {
        "role": "user",
        "content": "Write a bash script to backup a directory"
      }
    ],
    "max_tokens": 1000
  }'

Rate Limits

API rate limits vary by plan and model. Check response headers for current limits.

Plan
Requests/min
Tokens/min
Starter
20
40K
Pro
100
200K
Enterprise
Custom
Custom

Error Handling

The API returns standard HTTP status codes and JSON error responses.

400
Bad Request - Invalid request format
401
Unauthorized - Invalid API key
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error - Server issue