| | --- |
| | license: mit |
| | tags: |
| | - tutorial |
| | - crazyrouter |
| | - openai |
| | - api-gateway |
| | - getting-started |
| | - llm |
| | language: |
| | - en |
| | - zh |
| | --- |
| | |
| | # π Crazyrouter Getting Started Guide |
| |
|
| | > One API key. 624+ AI models. OpenAI-compatible. Get started in 60 seconds. |
| |
|
| | ## What is Crazyrouter? |
| |
|
| | [Crazyrouter](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community) is an AI API gateway. Instead of managing separate API keys for OpenAI, Anthropic, Google, DeepSeek, and dozens of other providers, you use **one key** to access them all. |
| |
|
| | It's fully **OpenAI SDK compatible** β just change the `base_url` and you're done. |
| |
|
| | --- |
| |
|
| | ## Step 1: Get Your API Key |
| |
|
| | 1. Go to [crazyrouter.com](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community) |
| | 2. Sign up (free tier available) |
| | 3. Copy your API key (`sk-...`) |
| |
|
| | --- |
| |
|
| | ## Step 2: Install the OpenAI SDK |
| |
|
| | ```bash |
| | pip install openai |
| | ``` |
| |
|
| | That's it. No special SDK needed. |
| |
|
| | --- |
| |
|
| | ## Step 3: Make Your First API Call |
| |
|
| | ### Python |
| |
|
| | ```python |
| | from openai import OpenAI |
| | |
| | client = OpenAI( |
| | base_url="https://crazyrouter.com/v1", |
| | api_key="sk-your-crazyrouter-key" |
| | ) |
| | |
| | # Use any model β GPT-4o, Claude, Gemini, DeepSeek... |
| | response = client.chat.completions.create( |
| | model="gpt-4o-mini", |
| | messages=[ |
| | {"role": "user", "content": "What is an API gateway?"} |
| | ] |
| | ) |
| | |
| | print(response.choices[0].message.content) |
| | ``` |
| |
|
| | ### cURL |
| |
|
| | ```bash |
| | curl https://crazyrouter.com/v1/chat/completions \ |
| | -H "Content-Type: application/json" \ |
| | -H "Authorization: Bearer sk-your-crazyrouter-key" \ |
| | -d '{ |
| | "model": "gpt-4o-mini", |
| | "messages": [{"role": "user", "content": "Hello!"}] |
| | }' |
| | ``` |
| |
|
| | ### JavaScript / Node.js |
| |
|
| | ```javascript |
| | import OpenAI from "openai"; |
| | |
| | const client = new OpenAI({ |
| | baseURL: "https://crazyrouter.com/v1", |
| | apiKey: "sk-your-crazyrouter-key", |
| | }); |
| | |
| | const response = await client.chat.completions.create({ |
| | model: "gpt-4o-mini", |
| | messages: [{ role: "user", content: "Hello from Node.js!" }], |
| | }); |
| | |
| | console.log(response.choices[0].message.content); |
| | ``` |
| |
|
| | --- |
| |
|
| | ## Step 4: Switch Models Instantly |
| |
|
| | The magic of Crazyrouter β switch between any model by changing one string: |
| |
|
| | ```python |
| | # OpenAI |
| | response = client.chat.completions.create(model="gpt-4o", messages=messages) |
| | |
| | # Anthropic Claude |
| | response = client.chat.completions.create(model="claude-sonnet-4-20250514", messages=messages) |
| | |
| | # Google Gemini |
| | response = client.chat.completions.create(model="gemini-2.0-flash", messages=messages) |
| | |
| | # DeepSeek |
| | response = client.chat.completions.create(model="deepseek-chat", messages=messages) |
| | |
| | # DeepSeek R1 (reasoning) |
| | response = client.chat.completions.create(model="deepseek-reasoner", messages=messages) |
| | ``` |
| |
|
| | No SDK changes. No config changes. Just the model name. |
| |
|
| | --- |
| |
|
| | ## Step 5: Streaming Responses |
| |
|
| | ```python |
| | stream = client.chat.completions.create( |
| | model="gpt-4o", |
| | messages=[{"role": "user", "content": "Write a short poem about coding"}], |
| | stream=True |
| | ) |
| | |
| | for chunk in stream: |
| | content = chunk.choices[0].delta.content |
| | if content: |
| | print(content, end="", flush=True) |
| | ``` |
| |
|
| | --- |
| |
|
| | ## Step 6: List Available Models |
| |
|
| | ```python |
| | models = client.models.list() |
| | for model in models.data: |
| | print(model.id) |
| | ``` |
| |
|
| | Or via cURL: |
| |
|
| | ```bash |
| | curl https://crazyrouter.com/v1/models \ |
| | -H "Authorization: Bearer sk-your-crazyrouter-key" |
| | ``` |
| |
|
| | --- |
| |
|
| | ## Popular Models |
| |
|
| | | Model | Provider | Best For | |
| | |-------|----------|----------| |
| | | `gpt-4o` | OpenAI | General purpose, vision | |
| | | `gpt-4o-mini` | OpenAI | Fast, cheap, good enough | |
| | | `claude-sonnet-4-20250514` | Anthropic | Coding, analysis | |
| | | `claude-haiku-3.5` | Anthropic | Fast, affordable | |
| | | `gemini-2.0-flash` | Google | Speed, long context | |
| | | `deepseek-chat` | DeepSeek | Cheap, strong coding | |
| | | `deepseek-reasoner` | DeepSeek | Complex reasoning (R1) | |
| | | `o3-mini` | OpenAI | Reasoning tasks | |
| |
|
| | --- |
| |
|
| | ## Environment Variables (Recommended) |
| |
|
| | ```bash |
| | export OPENAI_API_KEY="sk-your-crazyrouter-key" |
| | export OPENAI_BASE_URL="https://crazyrouter.com/v1" |
| | ``` |
| |
|
| | Then your code simplifies to: |
| |
|
| | ```python |
| | from openai import OpenAI |
| | client = OpenAI() # Reads from env vars automatically |
| | ``` |
| |
|
| | --- |
| |
|
| | ## FAQ |
| |
|
| | **Q: Is it really OpenAI-compatible?** |
| | A: Yes. Any tool that works with the OpenAI API works with Crazyrouter. Just change the base URL. |
| |
|
| | **Q: Is there a free tier?** |
| | A: Yes. Sign up at [crazyrouter.com](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community) to get started. |
| |
|
| | **Q: How many models are available?** |
| | A: 624+ models from 20+ providers, and growing. |
| |
|
| | **Q: Can I use it with LangChain / LlamaIndex / AutoGen?** |
| | A: Absolutely. See our [LangChain guide](https://huggingface.co/xujfcn/Crazyrouter-LangChain-Guide). |
| |
|
| | --- |
| |
|
| | ## Links |
| |
|
| | - π [Website](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community) |
| | - π€ [Live Demo](https://huggingface.co/spaces/xujfcn/Crazyrouter-Demo) |
| | - π° [Pricing](https://huggingface.co/spaces/xujfcn/Crazyrouter-Pricing) |
| | - π [Model Pricing Dataset](https://huggingface.co/datasets/xujfcn/Crazyrouter-Model-Pricing) |
| | - π¬ [Telegram Community](https://t.me/crazyrouter) |
| | - π¦ [Twitter @metaviiii](https://twitter.com/metaviiii) |
| |
|