Overview
With LangChain’s OpenAI components, you can send requests to Crazyrouter with:- recommended protocol:
OpenAI-compatible API - base URL:
https://crazyrouter.com/v1 - auth variable:
OPENAI_API_KEY - main Python package:
langchain-openai - main JavaScript / TypeScript package:
@langchain/openai
Best For
- developers integrating Crazyrouter into Python or Node.js applications
- teams building prompt chains, RAG, tool calling, or workflow orchestration
- users who want an abstraction layer instead of manually writing raw HTTP requests
- projects that want to keep future model switching flexible
Protocol Used
Recommended protocol:OpenAI-compatible API
Core Crazyrouter settings:
- Python:
api_key+base_url - JavaScript / TypeScript:
apiKey+configuration.baseURL
Prerequisites
| Item | Notes |
|---|---|
| Crazyrouter account | Create one at crazyrouter.com |
| Crazyrouter token | Create a dedicated token for your LangChain project |
| Python | Prefer Python 3.10+ |
| Node.js | Prefer Node.js 18+ |
| LangChain packages | langchain-openai for Python and @langchain/openai for JS / TS |
| Allowed models | Allow at least one chat model; if you use vector search, allow an embedding model too |
gpt-5.4claude-sonnet-4-6gemini-3-pro-previewtext-embedding-3-large
Full Python Path
Recommended Windows Path
Recommended macOS / Linux Path
Full JavaScript / TypeScript Path
Windows PowerShell
macOS / Linux
Detailed Setup
Step 1: Create a LangChain-specific Crazyrouter token
For the first pass, allow only:
gpt-5.4claude-sonnet-4-6text-embedding-3-large
Step 2: Set the environment variable first
- macOS / Linux
- Windows PowerShell
- Linux Bash
- macOS / Zsh
- Windows PowerShell
Step 5: Run the smallest JavaScript / TypeScript chat validation
Create Run:
test-langchain-chat.mjs:Python Examples
Minimal Chat Example
Embeddings Example
Prompt Chain Example
Minimal RAG Example
JavaScript / TypeScript Example
Minimal Chat Example
Recommended Model Setup
| Use case | Recommended model | Why |
|---|---|---|
| first-pass validation | gpt-5.4 | verified successfully in production on March 23, 2026, and best for proving that LangChain and Crazyrouter are connected |
| higher-quality long-form and complex chains | claude-sonnet-4-6 | better for complex explanation, summaries, and heavier reasoning |
| Gemini fallback path | gemini-3-pro-preview | useful as a second compatibility-validation path |
| vector retrieval | text-embedding-3-large | strong first embedding baseline |
Token Setup Best Practices
| Setting | Recommendation | Notes |
|---|---|---|
| dedicated token | Required | do not share LangChain project tokens with desktop clients |
| model allowlist | Strongly recommended | start with only the chat model plus embedding model you need |
| quota cap | Strongly recommended | chains, RAG, and agents can multiply spend quickly |
| environment split | Recommended | separate dev, staging, and production |
| leak response | Rotate immediately | never commit the key to Git |
Verification Checklist
- Python or Node.js runtime is ready
-
OPENAI_API_KEYis set correctly -
langchain-openaior@langchain/openaiis installed - the chat model is set to
https://crazyrouter.com/v1throughbase_urlorbaseURL - the first
Reply only OKrequest succeeds - Crazyrouter logs show the matching request
- if embeddings are used, the embedding model is also allowed
- if RAG is used, it was first validated on a tiny dataset
Common Errors And Fixes
| Symptom | Likely cause | Fix |
|---|---|---|
401 unauthorized | wrong, expired, or badly pasted OPENAI_API_KEY | generate a new token and set it again |
404 | wrong base_url or missing /v1 | use https://crazyrouter.com/v1 |
model not found | wrong model name or the token does not allow it | switch back to gpt-5.4 and check the allowlist |
| embeddings fail | the embedding model was not allowed | add text-embedding-3-large to the token allowlist |
| RAG fails in many places | too many components were added at once | go back to single-turn chat, then rebuild step by step |
| spend rises too quickly | chains, retrieval, and multi-turn agent loops are stacking cost | reduce scope and separate budgets by environment |
FAQ
Which protocol should LangChain use with Crazyrouter?
Use the OpenAI-compatible route.What base URL should I set?
Usehttps://crazyrouter.com/v1.
Which Python package should I use?
Preferlangchain-openai.
Which JavaScript / TypeScript package should I use?
Prefer@langchain/openai.
Why not jump straight into agents or large RAG pipelines?
Because once a LangChain flow becomes complex, debugging becomes much harder. Minimal chat first, then layer features gradually.If you are integrating Crazyrouter into a real application codebase, LangChain is still one of the most important framework guides to keep detailed and accurate.