Skip to main content
Content updated: 2026-06-09
LangChain 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
If you plan to integrate Crazyrouter into your own application code rather than just chatting in a desktop client, LangChain is usually the most natural engineering integration path.

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:
Typical syntax in LangChain:
  • Python: api_key + base_url
  • JavaScript / TypeScript: apiKey + configuration.baseURL

System Requirements and Prerequisites

Recommended initial whitelist:
  • gpt-5.5
  • claude-opus-4-8
  • gemini-3.1-pro
  • text-embedding-3-large

Complete Integration Path for Python Projects

If you want to run FAISS examples, also add:
If you want to run FAISS examples, also add:

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.5
  • claude-opus-4-8
  • text-embedding-3-large
If you later need more models, expand as needed, but stick to a minimum whitelist at first.
2

Step 2: Set up environment variables first

If you plan to develop long-term, persist the configuration:
3

Step 3: Complete the minimal Python chat validation

Create a new test_langchain_chat.py:
Run:
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 test-langchain-chat.mjs:
Run:
6

Step 6: Gradually add Embeddings, Prompt, RAG

It’s not recommended to start with complex pipelines. Suggested order:
  1. Run basic single-round chat first
  2. Next, run Prompt + Output Parser
  3. Then, connect Embeddings
  4. Finally, do RAG or Agent

Python Examples

Minimal Chat Example

Embeddings Example

Prompt Chain Example

Minimal RAG Example

JavaScript / TypeScript Examples

Minimal Chat Example

Best Practices for Token Settings

Verification Checklist

  • Python or Node.js runtime environment is ready
  • OPENAI_API_KEY is properly set
  • langchain-openai or @langchain/openai is installed
  • Chat model is set base_url / baseURL to https://api.crazyrouter.com/v1
  • The first Reply only OK request 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?

Enter https://api.crazyrouter.com/v1.

Which package should be used in Python?

Prefer langchain-openai.

Which package should be used in JavaScript / TypeScript?

Prefer @langchain/openai. 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.