更新日: 2026-06-06LangChain is one of the most common LLM application frameworks for chat flows, prompt chains, tool use, RAG, agent-style workflows, and application-level orchestration. For Crazyrouter, the most reliable route is LangChain’s official OpenAI-compatible component stack.
Overview
With LangChain’s OpenAI components, you can send requests to Crazyrouter with:- recommended protocol:
OpenAI-compatible API - base URL:
https://api.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
Suggested starter allowlist:
gpt-5.5claude-opus-4-8gemini-3.1-protext-embedding-3-large
Full Python Path
Recommended Windows Path
Recommended macOS / Linux Path
Full JavaScript / TypeScript Path
Windows PowerShell
macOS / Linux
Detailed Setup
1
Step 1: Create a LangChain-specific Crazyrouter token
For the first pass, allow only:
gpt-5.5claude-opus-4-8text-embedding-3-large
2
Step 2: Set the environment variable first
- macOS / Linux
- Windows PowerShell
- Linux Bash
- macOS / Zsh
- Windows PowerShell
3
Step 3: Run the smallest Python chat validation
Create Run:
test_langchain_chat.py:4
Step 4: Switch to the env-var version
Once the route works, avoid hard-coding the key:
5
Step 5: Run the smallest JavaScript / TypeScript chat validation
Create Run:
test-langchain-chat.mjs:6
Step 6: Add embeddings, prompts, and RAG gradually
Recommended order:
- single-turn chat first
- prompt + parser second
- embeddings third
- RAG or agent flows last
Python Examples
Minimal Chat Example
Embeddings Example
Prompt Chain Example
Minimal RAG Example
JavaScript / TypeScript Example
Minimal Chat Example
Recommended Model Setup
Token Setup Best Practices
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://api.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
FAQ
Which protocol should LangChain use with Crazyrouter?
Use the OpenAI-compatible route.What base URL should I set?
Usehttps://api.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.