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
- Install the chat model package. Add the agent package too if you want the tool loop:
pip install -U langchain langchain-openainpm install langchain @langchain/openai @langchain/core zod- 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.
export PENTESTLLM_API_KEY="sk-ptl-live-…"- Python: construct
ChatOpenAIwith three things, the id, the key and this base URL;invokegives back anAIMessagewhoseusage_metadataholds the billed token counts;streamhands 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.
import osfrom langchain_openai import ChatOpenAI model = ChatOpenAI( model="glm-5.3-uncensored", api_key=os.environ["PENTESTLLM_API_KEY"], base_url="https://api.pentestllm.ai/v1", max_tokens=1024, stream_usage=True, # token counts on streamed answers too; off by default once base_url is set) response = model.invoke("Explain, in three sentences, how SSRF reaches a cloud metadata endpoint.")print(response.content)print(response.usage_metadata) # {'input_tokens': …, 'output_tokens': …, 'total_tokens': …} for chunk in model.stream("List the response headers worth checking on an in-scope web target after recon."): print(chunk.content, end="", flush=True)init_chat_model produces the same object from a provider string, handy when the build comes from config:
from langchain.chat_models import init_chat_model model = init_chat_model( model="glm-5.3-flash-uncensored", model_provider="openai", base_url="https://api.pentestllm.ai/v1", api_key=os.environ["PENTESTLLM_API_KEY"],)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.
export OPENAI_API_KEY="sk-ptl-live-…"export OPENAI_BASE_URL="https://api.pentestllm.ai/v1"- JavaScript: identical three values, except the URL sits under
configuration.baseURL. Thatconfigurationobject is forwarded to the OpenAI SDK client, so any other client option belongs there as well.
import { ChatOpenAI } from "@langchain/openai"; const model = new ChatOpenAI({ model: "glm-5.3-uncensored", apiKey: process.env.PENTESTLLM_API_KEY, configuration: { baseURL: "https://api.pentestllm.ai/v1" }, maxTokens: 1024,}); const response = await model.invoke("Explain, in three sentences, how SSRF reaches a cloud metadata endpoint.");console.log(response.content);console.log(response.usage_metadata); // { input_tokens, output_tokens, total_tokens } const stream = await model.stream("List the response headers worth checking on an in-scope web target after recon.");for await (const chunk of stream) process.stdout.write(String(chunk.content));- 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).
import osfrom langchain.agents import create_agentfrom langchain.tools import toolfrom langchain_openai import ChatOpenAI @tooldef read_file(path: str) -> str: """Read a UTF-8 text file and return its contents.""" with open(path, encoding="utf-8") as f: return f.read() model = ChatOpenAI( model="glm-5.3-uncensored", api_key=os.environ["PENTESTLLM_API_KEY"], base_url="https://api.pentestllm.ai/v1",) agent = create_agent( model=model, tools=[read_file], system_prompt="You review Python code for vulnerabilities on an authorized engagement. Read a file before you comment on it.",) result = agent.invoke({"messages": [{"role": "user", "content": "Review ./app.py for injection and auth flaws."}]})print(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:
import { readFile } from "node:fs/promises";import { ChatOpenAI } from "@langchain/openai";import { createAgent, tool } from "langchain";import * as z from "zod"; const readTextFile = tool(async ({ path }) => readFile(path, "utf8"), { name: "read_file", description: "Read a UTF-8 text file and return its contents.", schema: z.object({ path: z.string() }),}); const model = new ChatOpenAI({ model: "glm-5.3-uncensored", apiKey: process.env.PENTESTLLM_API_KEY, configuration: { baseURL: "https://api.pentestllm.ai/v1" },}); const agent = createAgent({ model, tools: [readTextFile], systemPrompt: "You review TypeScript code for vulnerabilities on an authorized engagement. Read a file before you comment on it.",}); const result = await agent.invoke({ messages: [{ role: "user", content: "Review ./app.ts for injection and auth flaws." }] });console.log(result.messages.at(-1)?.content);Each setting, explained
- model
- glm-5.3-uncensoredthe 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/v1the request target; the client adds /chat/completions, which is why the trailing /v1 is required
- max_tokens / maxTokens
- 1024ceiling on output tokens per reply; each model page states the build’s maximum
- stream_usage
- TruePython 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
- Falsewhen True, invoke streams under the hood and assembles the reply; stream() always streams
- temperature, timeout, max_retries
- optionalsampling temperature, per-request timeout, and the number of automatic retries after a failed call
- tools / system_prompt
- create_agentwhich 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.
| Model | Cost per turn | Takes tools |
|---|---|---|
| GLM-5.3 Uncensored | $0.01 | see model page |
| GLM-5.3 Flash Uncensored | $0.0047 | see model page |
| DeepSeek V4.1 Flash Abliterated | $0.04 | see model page |
| DeepSeek V4 Pro Uncensored | $0.04 | see model page |
| GLM-5.3 Abliterated | $0.09 | see model page |
| GLM-5.3 Flash Code Uncensored | $0.25 | see model page |
| GLM-5.3 Uncensored | Uncensored | $0.282 | $0.846 |
| GLM-5.3 Flash Uncensored | Uncensored | $0.1053 | $0.3685 |
| DeepSeek V4.1 Flash Abliterated | Abliterated | $0.8488 | $1.6975 |
| DeepSeek V4 Pro Uncensored | Uncensored | $0.97 | $1.94 |
| GLM-5.3 Abliterated | Abliterated | $2.1825 | $4.365 |
| GLM-5.3 Flash Code Uncensored | Uncensored | $6.00 | $6.00 |
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:
curl 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.
curl -i https://api.pentestllm.ai/v1/chat/completions \ -H "Authorization: Bearer sk-ptl-live-…" \ -H "Content-Type: application/json" \ -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, orPENTESTLLM_API_KEYis 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_urlnever took effect and your key went to OpenAI.404 model_not_found: themodelvalue 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/completionsat the root, or it went to/responsesbecause you setuse_responses_api=True, or enabledreasoningor a built-in tool, both Responses-only. Only/v1/chat/completionsis 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-aftersays how long; withmax_retriesset the client waits and retries by itself.usage_metadatacomes backNoneon a Python stream: LangChain switchesstream_usageoff as soon asbase_urlis set. Give the constructor, or thestreamcall,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 defaultwith_structured_outputmethod has the same requirement;method="json_schema"instead needs a build that acceptsresponse_format. - The reply cuts off and
finish_reasonislength:max_tokensis 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.