SDKs & frameworksGuide reviewed 2026-09-13

LangChain, LlamaIndex & AI SDK

Use RouterPlex from the popular LLM frameworks.

Follow updates
On this page

The examples below use Chat Completions with RouterPlex. Run them on macOS, Linux, or Windows after setting your key and preparing your environment. Install only the framework you use.

LangChain — Python #

Install langchain-openai:

macOS/Linux:

bash
.venv/bin/python -m pip install --upgrade langchain-openai

Windows PowerShell:

powershell
.\.venv\Scripts\python.exe -m pip install --upgrade langchain-openai

Save as langchain-example.py:

python
import os
from langchain_openai import ChatOpenAI
 
llm = ChatOpenAI(
model="claude-sonnet-4-6",
base_url="https://api.routerplex.com/v1",
api_key=os.environ["ROUTERPLEX_API_KEY"],
use_responses_api=False,
max_tokens=256,
)
print(llm.invoke("Reply with exactly: RouterPlex connected.").content)

Run with your virtual environment's Python. ChatOpenAI follows OpenAI's API schema; provider-specific fields such as reasoning_content are not necessarily preserved.

LlamaIndex — Python #

Install the OpenAI-like integration:

macOS/Linux:

bash
.venv/bin/python -m pip install --upgrade llama-index-llms-openai-like

Windows PowerShell:

powershell
.\.venv\Scripts\python.exe -m pip install --upgrade llama-index-llms-openai-like

Save as llamaindex-example.py:

python
import os
from llama_index.llms.openai_like import OpenAILike
 
llm = OpenAILike(
model="claude-sonnet-4-6",
api_base="https://api.routerplex.com/v1",
api_key=os.environ["ROUTERPLEX_API_KEY"],
context_window=1000000,
is_chat_model=True,
is_function_calling_model=True,
max_tokens=256,
)
print(llm.complete("Reply with exactly: RouterPlex connected."))

When changing models, update the context window and function-calling flag from the catalog. OpenAILike avoids the official-OpenAI model-name validation of the standard wrapper.

Vercel AI SDK — JavaScript / TypeScript #

Install with npm install ai @ai-sdk/openai-compatible on macOS/Linux or npm.cmd install ai @ai-sdk/openai-compatible in PowerShell. Save as ai-sdk-example.mjs:

javascript
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
 
const routerplex = createOpenAICompatible({
name: "routerplex",
baseURL: "https://api.routerplex.com/v1",
apiKey: process.env.ROUTERPLEX_API_KEY,
});
const { text } = await generateText({
model: routerplex("claude-sonnet-4-6"),
maxOutputTokens: 256,
prompt: "Reply with exactly: RouterPlex connected.",
});
console.log(text);

Run node ai-sdk-example.mjs. Use this adapter for Chat Completions; do not assume another adapter's default selects the same API.

Verify and troubleshoot #

Each example should print a reply and create an entry in Usage. If it fails, try the Quickstart to distinguish an account/key problem from a framework configuration problem. Package versions in your project must be mutually compatible.

Official references: LangChain, LlamaIndex OpenAILike, AI SDK OpenAI-compatible provider.

LangChain, LlamaIndex & AI SDK — Docs