LangChain on an OpenAI compatible API, for security work

Python ChatOpenAI(base_url, api_key) or JavaScript configuration.baseURL, an uncensored build id, and the create_agent tool loop on it: usage, cost, errors.

Steps checked November 2, 2026 · prices as of November 18, 2026

A code-review agent that stops at the first exploit-shaped question is useless on an engagement. LangChain’s ChatOpenAI accepts a base URL and a key, so the chains and agents you already have can run on an uncensored build instead: one constructor in Python or JavaScript, an id from the models page, and create_agent drives its tool loop on it.

What you need

Nothing to click through: the endpoint and the key go into the constructor of LangChain’s OpenAI chat class. In Python that is ChatOpenAI from langchain-openai with base_url and api_key; in JavaScript it is ChatOpenAI from @langchain/openai with apiKey plus configuration.baseURL. init_chat_model and initChatModel accept the same pair alongside model_provider="openai".

Agents take that same instance. In LangChain 1.x the factory is create_agent (createAgent in JavaScript); LangGraph’s older create_react_agent now forwards to it. Either way you configure the endpoint on the model object once and every chain and agent inherits it.

Want to see a build answer before wiring anything? The prompt box on the home page gives a few free turns, and the playground runs any build in the browser with a key.

Shortest path to a first reply

  1. Install the chat model package. Add the agent package too if you want the tool loop:
shell
1pip install -U langchain langchain-openai
shell
1npm install langchain @langchain/openai @langchain/core zod
  1. Make a key in the console and export it. Every snippet reads the variable, so the key is never written into a file that ends up in a repo.
shell
1export PENTESTLLM_API_KEY="sk-ptl-live-…"
  1. Python: construct ChatOpenAI with three things, the id, the key and this base URL; invoke gives back an AIMessage whose usage_metadata holds the billed token counts; stream hands over chunks as they are generated. The ids used here (glm-5.3-uncensored, glm-5.3-flash-uncensored, deepseek-v4.1-flash-abliterated) are the three LangChain callers pick most on this API; swap in any id from the models page the same way.
python
1import os
2from langchain_openai import ChatOpenAI
3
4model = ChatOpenAI(
5 model="glm-5.3-uncensored",
6 api_key=os.environ["PENTESTLLM_API_KEY"],
7 base_url="https://api.pentestllm.ai/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("Explain, in three sentences, how SSRF reaches a cloud metadata endpoint.")
13print(response.content)
14print(response.usage_metadata) # {'input_tokens': …, 'output_tokens': …, 'total_tokens': …}
15
16for chunk in model.stream("List the response headers worth checking on an in-scope web target after recon."):
17 print(chunk.content, end="", flush=True)

init_chat_model produces the same object from a provider string, handy when the build comes from config:

python
1from langchain.chat_models import init_chat_model
2
3model = init_chat_model(
4 model="glm-5.3-flash-uncensored",
5 model_provider="openai",
6 base_url="https://api.pentestllm.ai/v1",
7 api_key=os.environ["PENTESTLLM_API_KEY"],
8)

You can also leave both values to the environment. LangChain reads api_key from OPENAI_API_KEY and base_url from OPENAI_API_BASE, then OPENAI_BASE_URL; once those are exported, ChatOpenAI(model="…") on its own hits this API. If the same process also calls OpenAI, keep the explicit arguments, or both clients end up on one base URL.

shell
1export OPENAI_API_KEY="sk-ptl-live-…"
2export OPENAI_BASE_URL="https://api.pentestllm.ai/v1"
  1. JavaScript: identical three values, except the URL sits under configuration.baseURL. That configuration object is forwarded to the OpenAI SDK client, so any other client option belongs there as well.
typescript
1import { ChatOpenAI } from "@langchain/openai";
2
3const model = new ChatOpenAI({
4 model: "glm-5.3-uncensored",
5 apiKey: process.env.PENTESTLLM_API_KEY,
6 configuration: { baseURL: "https://api.pentestllm.ai/v1" },
7 maxTokens: 1024,
8});
9
10const response = await model.invoke("Explain, in three sentences, how SSRF reaches a cloud metadata endpoint.");
11console.log(response.content);
12console.log(response.usage_metadata); // { input_tokens, output_tokens, total_tokens }
13
14const stream = await model.stream("List the response headers worth checking on an in-scope web target after recon.");
15for await (const chunk of stream) process.stdout.write(String(chunk.content));
  1. Agent: pass the instance and your tools to create_agent. The loop asks the model, executes the tool it requested, appends the output and asks again until the model replies in plain text. The example is a code reviewer for an authorized engagement that reads the file before it judges it. Use an id whose model page shows tool calls (the table further down says which).
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="glm-5.3-uncensored",
16 api_key=os.environ["PENTESTLLM_API_KEY"],
17 base_url="https://api.pentestllm.ai/v1",
18)
19
20agent = create_agent(
21 model=model,
22 tools=[read_file],
23 system_prompt="You review Python code for vulnerabilities on an authorized engagement. Read a file before you comment on it.",
24)
25
26result = agent.invoke({"messages": [{"role": "user", "content": "Review ./app.py for injection and auth flaws."}]})
27print(result["messages"][-1].content)

Existing code on LangGraph’s create_react_agent runs unchanged with the same model and tools (there the system prompt is the prompt argument); its deprecation message points at the import used above. In JavaScript the agent looks the same:

typescript
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: "glm-5.3-uncensored",
14 apiKey: process.env.PENTESTLLM_API_KEY,
15 configuration: { baseURL: "https://api.pentestllm.ai/v1" },
16});
17
18const agent = createAgent({
19 model,
20 tools: [readTextFile],
21 systemPrompt: "You review TypeScript code for vulnerabilities on an authorized engagement. Read a file before you comment on it.",
22});
23
24const result = await agent.invoke({ messages: [{ role: "user", content: "Review ./app.ts for injection and auth flaws." }] });
25console.log(result.messages.at(-1)?.content);

Each setting, explained

model
glm-5.3-uncensored
the id exactly as the models page writes it; sent as each request’s model field
api_key / apiKey
os.environ["PENTESTLLM_API_KEY"]
the full sk-ptl- key, sent as Authorization: Bearer; when unset, Python reads OPENAI_API_KEY instead
base_url / configuration.baseURL
https://api.pentestllm.ai/v1
the request target; the client adds /chat/completions, which is why the trailing /v1 is required
max_tokens / maxTokens
1024
ceiling on output tokens per reply; each model page states the build’s maximum
stream_usage
True
Python only: requests the usage chunk on a stream. LangChain disables it whenever base_url is set; this API returns it, so re-enable it. JavaScript has it on by default as streamUsage
streaming
False
when True, invoke streams under the hood and assembles the reply; stream() always streams
temperature, timeout, max_retries
optional
sampling temperature, per-request timeout, and the number of automatic retries after a failed call
tools / system_prompt
create_agent
which functions the agent is allowed to call, and the message placed first in every call; in createAgent the field is systemPrompt

Which build to put in model

Requests leave ChatOpenAI in OpenAI format, which each build on the models page understands, so for plain invoke and stream any id is fine. The agent loop needs tool calls; so does bind_tools, and so does with_structured_output in its default method, since that is function calling underneath. Late in a review session a single turn carries the whole conversation, every file read and every tool result, so the input side dominates the bill and the build with the lowest input price has the lowest cost per turn.

ModelCost per turnTakes tools
GLM-5.3 Uncensored$0.01see model page
GLM-5.3 Flash Uncensored$0.0047see model page
DeepSeek V4.1 Flash Abliterated$0.04see model page
DeepSeek V4 Pro Uncensored$0.04see model page
GLM-5.3 Abliterated$0.09see model page
GLM-5.3 Flash Code Uncensored$0.25see model page

A turn of 40,000 input and 1,200 output tokens at the catalog prices of 2026-11-18. The tool column is what the catalog publishes; where it publishes nothing, the model page decides.

Uncensored models and their prices per million tokens
GLM-5.3 Uncensoredglm-5.3-uncensoredUncensored$0.282$0.846
GLM-5.3 Flash Uncensoredglm-5.3-flash-uncensoredUncensored$0.1053$0.3685
DeepSeek V4.1 Flash Abliterateddeepseek-v4.1-flash-abliteratedAbliterated$0.8488$1.6975
DeepSeek V4 Pro Uncensoreddeepseek-v4-pro-uncensoredUncensored$0.97$1.94
GLM-5.3 Abliteratedglm-5.3-abliteratedAbliterated$2.1825$4.365
GLM-5.3 Flash Code Uncensoredglm-5.3-flash-code-uncensoredUncensored$6.00$6.00

Prices per million tokens, read from the live catalog on 2026-11-18.

For agents that write and fix code, the uncensored coding AI guide sets the code builds side by side and prices a full day on each. The same ids go into Cursor, OpenCode and Claude Code, and the refusals page explains why testers move an agent off the stock model in the first place.

Prove the key works

Ask the API which ids your key may call; the one you set in model has to appear:

shell
1curl https://api.pentestllm.ai/v1/models -H "Authorization: Bearer sk-ptl-live-…"

Next, make one request shaped like the ones ChatOpenAI sends. With -i the headers print too: one names the request, and on a non-streamed reply another states the charge in USD.

shell
1curl -i https://api.pentestllm.ai/v1/chat/completions \
2 -H "Authorization: Bearer sk-ptl-live-…" \
3 -H "Content-Type: application/json" \
4 -d '{"model": "glm-5.3-uncensored", "messages": [{"role": "user", "content": "Reply with the single word ok."}]}'

Now execute either snippet above. usage_metadata on the reply carries the billed input and output tokens, and the console’s usage page shows the same request with its charge. On a stream the counts ride on the final chunk, and in Python only when stream_usage=True.

When it fails

  • 401 invalid_api_key: a wrong or revoked key, or PENTESTLLM_API_KEY is missing from the shell that launched the script. Re-export it or recopy it from the console. If the 401 body talks about OpenAI, base_url never took effect and your key went to OpenAI.
  • 404 model_not_found: the model value is not an id on the models page; compare the spelling. 404 route_not_found: the request landed on a path this API does not serve. Either the base URL lacks /v1, so the client posted /chat/completions at the root, or it went to /responses because you set use_responses_api=True, or enabled reasoning or a built-in tool, both Responses-only. Only /v1/chat/completions is served here; leave those off.
  • 402 insufficient_balance: too little credit for the request; add some in the console. 402 monthly_limit_reached: the monthly cap you set on the key is used up.
  • 403 scope_denied: the key was restricted to a set of models that does not include this one.
  • 429 rate_limited: the key’s rate limit tripped. retry-after says how long; with max_retries set the client waits and retries by itself.
  • usage_metadata comes back None on a Python stream: LangChain switches stream_usage off as soon as base_url is set. Give the constructor, or the stream call, stream_usage=True.
  • The agent writes prose and never touches a tool, or the request errors on tools: this build does not accept tool calls. Switch to a build whose page shows them. The default with_structured_output method has the same requirement; method="json_schema" instead needs a build that accepts response_format.
  • The reply cuts off and finish_reason is length: max_tokens is below what the answer needs. Raise it, up to the model page’s maximum.

Questions

No. ChatOpenAI speaks the OpenAI request format and only reaches OpenAI when no base URL is given. Point base_url (Python) or configuration.baseURL (JavaScript) at this API with a console key, and your existing class, chains and agents then run on an uncensored build without any OpenAI account.

Only if you ask it to, with use_responses_api=True, or by enabling a Responses-only option like reasoning or a built-in tool. Its default route is Chat Completions, which is what this API serves; keep those off and invoke, stream, bind_tools and create_agent stay on Chat Completions.

Any id on the models page. Each responds on /v1/chat/completions in OpenAI format under one key; write the id as the page does. If you need the agent loop, bind_tools or default structured output, pick one whose page shows tool calls; the table above shows which do. See the models page.

It accepts OpenAI-shaped requests on /v1/chat/completions and sends OpenAI-shaped responses back, so an OpenAI client needs only a new base URL and key. This API qualifies, ChatOpenAI is one of those clients, and the usage_metadata on every reply holds the billed tokens, charged per token against your prepaid credit.

Every model above is on the uncensored model list with its live price per million tokens. Per-token pricing sets the whole catalog side by side, and the family directory groups the builds by base model.

Get a keyPrepaid from $10, no subscription.

New models and price changes, once a month.

New uncensored builds with their prices, price moves, and what the daily model check found.

Help