prxy.monster API-key BYOK is live. Start free

Using prxy.monster with LangChain JS

LangChain JS uses provider chat models (ChatOpenAI, ChatAnthropic) that accept a configuration.baseURL (OpenAI) or clientOptions.baseURL (Anthropic) override. One arg per model — every chain, agent, and LangGraph node built on top inherits it.

Install

You probably have these already.

npm install @langchain/openai @langchain/anthropic @langchain/core

Configure

You can either set env vars OR pass options explicitly. Both work; explicit is clearer when reviewing code.

import { ChatOpenAI } from '@langchain/openai';
 
const llm = new ChatOpenAI({
  model: 'gpt-4o',
  apiKey: process.env.OPENAI_API_KEY, // your prxy key
  configuration: {
    baseURL: 'https://api.prxy.monster/v1',
  },
});
 
const r = await llm.invoke('hi');

Code change

If you used env vars: zero. If you wired explicit configuration: the baseURL line above is the only diff.

Verify

curl https://api.prxy.monster/health

Build a one-line chain and run it — successful response confirms routing.

What you get

How this composes with LangChain memory

LangChain memory (BufferMemory, SummaryMemory, etc.) lives inside your chain. prxy.monster lives between your chain and the LLM. They don’t conflict — they handle different layers:

ConcernLangChain memoryprxy.monster
Per-chain conversation stateYesNo
Cross-chain cachingNoYes (semantic-cache)
Cross-session pattern learningNoYes (patterns)
Token-budget managementManualAutomatic (ipc, cost-guard)
Tool-def overheadNoYes (mcp-optimizer)

Use both. They compose cleanly.

LangGraph

LangGraph wraps the same chat models. Set baseURL on the underlying ChatOpenAI / ChatAnthropic instance you pass to nodes — every node inherits it.

import { ChatAnthropic } from '@langchain/anthropic';
import { StateGraph } from '@langchain/langgraph';
 
const llm = new ChatAnthropic({
  model: 'claude-sonnet-4-6',
  clientOptions: { baseURL: 'https://api.prxy.monster' },
});
 
// Every node that uses `llm` now goes through prxy.monster
const graph = new StateGraph(...)
  .addNode('reason', async (state) => llm.invoke(state.messages))
  .addNode('answer', async (state) => llm.invoke(state.messages))
  .compile();

LangSmith tracing is unaffected — traces happen client-side before the request leaves your process.

For RAG / chain workflows:

PRXY_PIPE=semantic-cache,patterns,ipc,cost-guard

For agentic workflows with tool use:

PRXY_PIPE=mcp-optimizer,semantic-cache,patterns,ipc

Common issues

Full example

LangChain RAG pipeline with semantic caching: github.com/Ekkos-Technologies-Inc/prxy-monster-examples/tree/main/examples/langchain-rag

Verify the exact constructor option name (configuration.baseURL for OpenAI, clientOptions.baseURL for Anthropic) with the LangChain JS docs for your installed version.