Content updated: 2026-06-09LangChain is one of the most commonly used frameworks for developing LLM applications. It is suitable for wrapping chat interfaces, prompt chains, tool calling, RAG, agent workflows, and application-level orchestration. The most reliable way to connect Crazyrouter is by using the OpenAI-compatible components officially supported by LangChain.
Overview
With LangChain’s OpenAI component, you can send requests to Crazyrouter:- Recommended protocol:
OpenAI-compatible API - Base URL:
https://api.crazyrouter.com/v1 - Authentication variable:
OPENAI_API_KEY - Main Python package:
langchain-openai - Main JavaScript / TypeScript package:
@langchain/openai
Who Is It For
- Developers looking to properly integrate Crazyrouter into Python or Node.js projects
- People wanting to build prompt chains, RAG, tool calling, or workflow orchestration
- Those wanting to abstract model calling logic uniformly instead of writing low-level HTTP requests directly
- Those wanting flexibility to switch models or upstream providers in the future
Usage Protocol
Recommended protocol:OpenAI-compatible API
Corresponding core configuration for Crazyrouter:
- Python:
api_key+base_url - JavaScript / TypeScript:
apiKey+configuration.baseURL
System Requirements and Prerequisites
Recommended initial whitelist:
gpt-5.5claude-opus-4-8gemini-3.1-protext-embedding-3-large
Complete Integration Path for Python Projects
Recommended Path for Windows
Recommended Path for macOS / Linux
Complete Integration Path for JavaScript / TypeScript Projects
Windows PowerShell
macOS / Linux
Complete Setup From Scratch
1
Step 1: Create a dedicated LangChain token in Crazyrouter
For the first time, it’s recommended to only enable:
gpt-5.5claude-opus-4-8text-embedding-3-large
2
Step 2: Set up environment variables first
- macOS / Linux
- Windows PowerShell
- Linux Bash
- macOS / Zsh
- Windows PowerShell
3
Step 3: Complete the minimal Python chat validation
Create a new Run:
test_langchain_chat.py:4
Step 4: Change to the environment variable version
After running successfully, it’s recommended not to hardcode your key in the code:
5
Step 5: Complete the minimal JavaScript / TypeScript chat validation
Create Run:
test-langchain-chat.mjs:6
Step 6: Gradually add Embeddings, Prompt, RAG
It’s not recommended to start with complex pipelines. Suggested order:
- Run basic single-round chat first
- Next, run Prompt + Output Parser
- Then, connect Embeddings
- Finally, do RAG or Agent
Python Examples
Minimal Chat Example
Embeddings Example
Prompt Chain Example
Minimal RAG Example
JavaScript / TypeScript Examples
Minimal Chat Example
Recommended Model Configuration
Best Practices for Token Settings
Verification Checklist
- Python or Node.js runtime environment is ready
-
OPENAI_API_KEYis properly set -
langchain-openaior@langchain/openaiis installed - Chat model is set
base_url/baseURLtohttps://api.crazyrouter.com/v1 - The first
Reply only OKrequest returns successfully - Corresponding request visible in Crazyrouter backend logs
- If using embeddings, embedding model is enabled
- If using RAG, first verify with minimal text set
Common Errors and Fixes
FAQ
What protocol should LangChain use to connect to Crazyrouter?
Prefer OpenAI-compatible protocol.What should be entered for Base URL?
Enterhttps://api.crazyrouter.com/v1.
Which package should be used in Python?
Preferlangchain-openai.
Which package should be used in JavaScript / TypeScript?
Prefer@langchain/openai.
Why is it not recommended to start with Agent or large-scale RAG the first time?
Because LangChain pipelines become significantly harder to troubleshoot as complexity increases. Start with minimal chat and add components step by step for stability.If you’re planning to officially integrate Crazyrouter into your application engineering, LangChain remains one of the most worthwhile development framework documents to prioritize.