DEV Community

Alex Spinov
Alex Spinov

Posted on

OpenRouter Has a Free API — Access GPT-4, Claude, Llama, and 200+ AI Models with One Endpoint

OpenRouter is a unified API gateway that gives you access to 200+ AI models from OpenAI, Anthropic, Google, Meta, Mistral, and more — all through a single OpenAI-compatible endpoint.

Free tier available. Some models are completely free. No credit card required to start.

Why Use OpenRouter?

  • One API, 200+ models — GPT-4o, Claude 3.5, Llama 3.1, Gemini, Mistral, and more
  • Free models — several models available at zero cost
  • OpenAI-compatible — change one line of code to switch from OpenAI
  • Automatic fallback — if one provider is down, routes to another
  • Price comparison — see cost per token across providers

Quick Setup

1. Get API Key

Sign up at openrouter.ai → Dashboard → Keys → Create Key (free).

2. Chat Completion

curl -s https://openrouter.ai/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -d '{
    "model": "meta-llama/llama-3.1-8b-instruct:free",
    "messages": [{"role": "user", "content": "What is web scraping and when is it legal?"}]
  }' | jq '.choices[0].message.content'
Enter fullscreen mode Exit fullscreen mode

3. List Available Models

# All models (no auth needed)
curl -s https://openrouter.ai/api/v1/models | jq '.data[] | {id: .id, pricing: .pricing, context_length: .context_length}' | head -30

# Free models only
curl -s https://openrouter.ai/api/v1/models | jq '.data[] | select(.pricing.prompt == "0") | .id'
Enter fullscreen mode Exit fullscreen mode

4. Use with OpenAI SDK

from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key="your-openrouter-key"
)

# Use any model
response = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Compare BeautifulSoup vs Scrapy for web scraping"}]
)
print(response.choices[0].message.content)

# Try a free model
free_response = client.chat.completions.create(
    model="meta-llama/llama-3.1-8b-instruct:free",
    messages=[{"role": "user", "content": "Write a Python hello world"}]
)
print(free_response.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

5. Streaming

stream = client.chat.completions.create(
    model="google/gemini-pro-1.5",
    messages=[{"role": "user", "content": "List top 10 web scraping tools"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
Enter fullscreen mode Exit fullscreen mode

6. Check Usage & Credits

curl -s https://openrouter.ai/api/v1/auth/key \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" | jq '{usage: .data.usage, limit: .data.limit, remaining: (.data.limit - .data.usage)}'
Enter fullscreen mode Exit fullscreen mode

Free Models (as of 2026)

Model Provider Context
Llama 3.1 8B Instruct Meta 131K
Gemma 2 9B Google 8K
Phi-3 Mini Microsoft 128K
Qwen 2 7B Alibaba 32K
Mistral 7B Mistral 32K

Key Endpoints

Endpoint Description
/api/v1/chat/completions Chat (OpenAI-compatible)
/api/v1/models List all models
/api/v1/auth/key Check API key & usage
/api/v1/generation Get generation details

Need custom data extraction or scraping solution? I build production-grade scrapers for any website. Email: Spinov001@gmail.com | My Apify Actors

Top comments (0)