メインコンテンツへスキップ
更新日: 2026-06-06
LangChain 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
If you are integrating Crazyrouter into real application code rather than just chatting in a desktop client, LangChain is often the most natural engineering path.

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:
In LangChain, that usually maps to:
  • Python: api_key + base_url
  • JavaScript / TypeScript: apiKey + configuration.baseURL

Prerequisites

Suggested starter allowlist:
  • gpt-5.5
  • claude-opus-4-8
  • gemini-3.1-pro
  • text-embedding-3-large

Full Python Path

If you want the FAISS example too:
If you want the FAISS example too:

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.5
  • claude-opus-4-8
  • text-embedding-3-large
Add more models only after the basic route is already stable.
2

Step 2: Set the environment variable first

If you want a persistent setup:
3

Step 3: Run the smallest Python chat validation

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

Step 6: Add embeddings, prompts, and RAG gradually

Recommended order:
  1. single-turn chat first
  2. prompt + parser second
  3. embeddings third
  4. RAG or agent flows last

Python Examples

Minimal Chat Example

Embeddings Example

Prompt Chain Example

Minimal RAG Example

JavaScript / TypeScript Example

Minimal Chat Example

Token Setup Best Practices

Verification Checklist

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

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

Which Python package should I use?

Prefer langchain-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.