LangChain with every AI model.

A Python and JavaScript framework for LLM apps and agents whose ChatOpenAI class takes a custom base URL. With a Nerdly key it reaches 503 models on one balance, paid per prompt.

Set it up

You need a Nerdly key (it starts with sk-nerd-): sign in on the API page to get one, and add credit in Billing.

  1. Install the chat model package, and the agent package for the tool loop.
    shell
    1pip install -U langchain langchain-openai
    2npm install langchain @langchain/openai @langchain/core zod
  2. Put the key in an environment variable; the code reads it.
    shell
    1export NERDLY_API_KEY="sk-nerd-…"
  3. Python: construct ChatOpenAI with the model id, the key and the base URL.
    python
    1import os
    2from langchain_openai import ChatOpenAI
    3
    4model = ChatOpenAI(
    5 model="deepseek-v4-flash-0731",
    6 api_key=os.environ["NERDLY_API_KEY"],
    7 base_url="https://api.nerdly.us/v1",
    8 max_tokens=1024,
    9 stream_usage=True, # token counts on streamed answers too; off by default once base_url is set
    10)
    11
    12response = model.invoke("Write a Python function that checks if a string is a palindrome.")
    13print(response.content)
    14print(response.usage_metadata)
  4. init_chat_model builds the same object from a provider name.
    python
    1import os
    2from langchain.chat_models import init_chat_model
    3
    4model = init_chat_model(
    5 model="deepseek-v4-flash-0731",
    6 model_provider="openai",
    7 base_url="https://api.nerdly.us/v1",
    8 api_key=os.environ["NERDLY_API_KEY"],
    9)
  5. JavaScript: the same three values, with the URL under configuration.baseURL.
    ts
    1import { ChatOpenAI } from "@langchain/openai";
    2
    3const model = new ChatOpenAI({
    4 model: "deepseek-v4-flash-0731",
    5 apiKey: process.env.NERDLY_API_KEY,
    6 configuration: { baseURL: "https://api.nerdly.us/v1" },
    7 maxTokens: 1024,
    8});
    9
    10const response = await model.invoke("Write a Python function that checks if a string is a palindrome.");
    11console.log(response.content);
  6. Agent: hand the model to create_agent with your tools; use a model that takes tool calls.
    python
    1import os
    2from langchain.agents import create_agent
    3from langchain.tools import tool
    4from langchain_openai import ChatOpenAI
    5
    6
    7@tool
    8def read_file(path: str) -> str:
    9 """Read a UTF-8 text file and return its contents."""
    10 with open(path, encoding="utf-8") as f:
    11 return f.read()
    12
    13
    14model = ChatOpenAI(
    15 model="deepseek-v4-flash-0731",
    16 api_key=os.environ["NERDLY_API_KEY"],
    17 base_url="https://api.nerdly.us/v1",
    18)
    19
    20agent = create_agent(
    21 model=model,
    22 tools=[read_file],
    23 system_prompt="You review Python code. Read a file before you comment on it.",
    24)
    25
    26result = agent.invoke({"messages": [{"role": "user", "content": "Review ./app.py for bugs."}]})
    27print(result["messages"][-1].content)
  7. The JavaScript agent is the same shape with createAgent.
    ts
    1import { readFile } from "node:fs/promises";
    2import { ChatOpenAI } from "@langchain/openai";
    3import { createAgent, tool } from "langchain";
    4import * as z from "zod";
    5
    6const readTextFile = tool(async ({ path }) => readFile(path, "utf8"), {
    7 name: "read_file",
    8 description: "Read a UTF-8 text file and return its contents.",
    9 schema: z.object({ path: z.string() }),
    10});
    11
    12const model = new ChatOpenAI({
    13 model: "deepseek-v4-flash-0731",
    14 apiKey: process.env.NERDLY_API_KEY,
    15 configuration: { baseURL: "https://api.nerdly.us/v1" },
    16});
    17
    18const agent = createAgent({
    19 model,
    20 tools: [readTextFile],
    21 systemPrompt: "You review TypeScript code. Read a file before you comment on it.",
    22});
    23
    24const result = await agent.invoke({ messages: [{ role: "user", content: "Review ./app.ts for bugs." }] });
    25console.log(result.messages.at(-1)?.content);

The examples use deepseek-v4-flash-0731, the most used coding model on Nerdly today; put any id from the models page in its place.

Which model to pick

  • Qwen4 35B A3B Uncensored (qwen4-35b-a3b-uncensored): $0.48 in, $2.40 out per million tokens, 1M context, about 1.4¢ an agent step.
  • Ergo Uncensored (ergo-uncensored): $4.40 in, $13.32 out per million tokens, 1M context, about $0.11 an agent step.
  • GLM-5.3 Abliterated (glm-5.3-abliterated): $2.33 in, $4.66 out per million tokens, 131K context, about 5.6¢ an agent step.
  • DeepSeek V4 Flash 0731 (deepseek-v4-flash-0731): $0.08 in, $0.12 out per million tokens, 1M context, about 0.19¢ an agent step.
  • DeepSeek V4.1 Flash 1017 (deepseek-v4.1-flash-1017): $0.25 in, $1.20 out per million tokens, 1M context, about 0.74¢ an agent step.
  • Claude Opus 5.5 (claude-opus-5-5): $2.80 in, $10 out per million tokens, 1M context, about 7.6¢ an agent step.

What a session costs

50 chat turns (about 2,000 tokens in and 500 out each) on DeepSeek V4 Flash 0731 cost about 1.1¢, paid from your balance. Every request LangChain sends is priced by its tokens at the model’s rate; a cheaper model costs less, a larger one more.

Things that trip people up

  • Python’s stream_usage stays off whenever base_url is set, so usage_metadata is None on streams until you pass stream_usage=True.
  • A base URL missing its /v1 makes the client post to /chat/completions at the host root and get a 404.
  • A 401 whose body names OpenAI means base_url was never set and the request went to OpenAI with this key.
  • api_key falls back to OPENAI_API_KEY and base_url to OPENAI_API_BASE, then OPENAI_BASE_URL; keep explicit arguments in code that also talks to OpenAI.
  • The agent loop, bind_tools and the default with_structured_output method all need a model that takes tool calls.
  • LangGraph’s create_react_agent is deprecated in favour of create_agent; its system prompt argument is prompt.

LangChain’s own documentation: docs.langchain.com/oss/python/integrations/chat/openai.

More guides

Questions.

Something else? Email hello@nerdly.us

Yes. LangChain speaks the OpenAI format, which Nerdly serves for every model in its catalog. Set the base URL and your Nerdly key as above and pick any model id.

Any model in the catalog; the table above lists good starting points with live prices. You can switch models at any time by changing the id.

LangChain itself is not billed by us; each request it sends is paid from your Nerdly balance at the model’s price per million tokens. As a guide, 50 chat turns (about 2,000 tokens in and 500 out each) on DeepSeek V4 Flash 0731 cost about 1.1¢. Top up from $10; nothing renews.

The key is missing, mistyped or revoked. Keys start with sk-nerd-; check there is no space or quote around it, and that LangChain is sending it to https://api.nerdly.us and not to another provider.

Use the exact model id from the models page (for example claude-sonnet-5-5, not "Claude Sonnet"). GET https://api.nerdly.us/v1/models lists every id without a key.

Your balance does not cover the request. Add funds in Billing; plans include their models only in Nerdly’s own Chat and Code.

Run LangChain on any model.

Get a key, add credit from $10, and point the tool at Nerdly.

Get a key
Join on TelegramHelp