EN ▾
Get API key

Updated

LangChain Model Not Found: Causes and Fixes

A LangChain model not found error with an OpenAI-compatible API almost always means the client is still asking for a default OpenAI model, or is talking to the wrong URL. The fixes below take a few minutes.

Two chain links joined by a glowing connector, representing LangChain linked to an API endpoint

No card needed. After sign-up, claim $0.50 of free test credit with one click (once per person).

Get API key

Key points

Quick fix: the three settings that must be right

If you are hitting a langchain model not found error, check three values before anything else. They are the model name, the base URL and the key. Everything below is a more detailed look at those three.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.uncensoredimage.com/v1",
    api_key="YOUR_KEY",
)

print(llm.invoke("Say hello in five words.").content)

The model ID for this service is uncensored. It is the only one. Names such as gpt-4o, gpt-3.5-turbo or anything copied from a tutorial will fail, because this endpoint serves a single open-weight model run by an independent provider. It is not a router across vendors, so it does not map other model names onto it.

Get your key from the API key page. The key goes in the Authorization: Bearer header, which the OpenAI client does for you.

Why the error appears in the first place

LangChain wraps the OpenAI client. When you create ChatOpenAI without arguments, it fills in a default model name and sends requests to the standard OpenAI address. Two things can go wrong when you point it at a compatible server.

  • Right URL, wrong model. The request reaches the server, the server looks for the model name you sent, and does not have it. The server says so, and LangChain shows the message as a model-not-found style error.
  • Wrong URL. The request goes somewhere that has never heard of your key or your model. The failure may look like a missing model, a 404, or an auth error, depending on where it lands.

The wording differs between versions of LangChain and the OpenAI SDK, and I cannot tell you the exact text your stack will print. The method is the same: look at which URL the request went to, and which model name was in the body. The next sections show how to see both.

Check the endpoint with curl before touching LangChain

Removing the framework from the picture is the fastest way to find out which side is wrong. Call the models route first:

curl https://api.uncensoredimage.com/v1/models \
  -H "Authorization: Bearer $API_KEY"

You should see a JSON list that includes uncensored. If that works, your key and URL are fine and the problem is in your LangChain configuration. Then try a chat request with the same model:

curl https://api.uncensoredimage.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"ping"}]}'

If curl succeeds and Python fails, compare the two. The only differences should be in how the client builds the URL and body. If curl also fails, read the status code: 401 points at the key, 429 means a limit (see below), and a connection error points at a typo in the host name.

Common causes, in order of how often they bite

1. Default model name left in place

Some LangChain classes accept model, some older examples use model_name. Both map to the same field. If you set neither, a default is used. Always pass the name yourself.

2. Base URL without /v1

The client appends /chat/completions to whatever you give it. The base URL for this site is https://api.uncensoredimage.com/v1, including /v1. Without the suffix, requests go to a path that does not exist.

3. Trailing path or double slash

Do not add /chat/completions to the base URL yourself. That produces a doubled path. Use the base only.

4. Environment variables overriding code

Depending on the version, OPENAI_API_BASE or OPENAI_BASE_URL may be read from the environment. A leftover value from an old project can win over what you intended, or fill a gap you forgot. Print them and unset what you do not want:

env | grep -i openai
unset OPENAI_API_BASE OPENAI_BASE_URL

5. A different provider class

Using classes meant for other vendors, for example one that hard-codes its own model list, will reject uncensored before any request is sent. Use ChatOpenAI from langchain_openai and pass the base URL.

6. Stale cached client or notebook state

In Jupyter, the old object may still be alive after you edit a cell. Restart the kernel after changing configuration.

A short debugging checklist

When the error persists, work through this list in order and stop at the first item that changes the result.

  1. Run the models call with curl. If uncensored is not listed, your key or host is wrong, and LangChain is not the problem.
  2. Run the chat call with curl. If it works, the server side is healthy.
  3. Print the client settings in your code. In Python, llm.model_name and llm.openai_api_base show what the object will use. Check that they match what you typed.
  4. Turn on debug logging for the HTTP library, or run the request through a local proxy, to see the real URL and body. Look at the path, which should end in /v1/chat/completions, and at the model field in the JSON.
  5. Remove every optional argument. Extra keyword arguments, such as a custom model_kwargs entry copied from another project, sometimes override the field you care about.
  6. Upgrade langchain-openai and openai together. Mixed versions can rename arguments in ways that quietly drop your base URL.

Most people find the cause at step 1 or 3. The pattern is almost always a name or address that differs by one character from what the server expects.

If you work from a config file, check how it is loaded as well. A YAML or JSON setting with the key spelled base_url in one place and openai_api_base in another is a classic source of two clients in the same project, one working and one not. Search the project for every place a chat model is built, because libraries that sit on top of LangChain, such as agent frameworks, sometimes build their own client with defaults and ignore yours. Give each of them the same three values and the problem disappears.

Node.js and LangChain.js

The JavaScript package takes the base URL inside a configuration object.

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "uncensored",
  apiKey: process.env.API_KEY,
  configuration: { baseURL: "https://api.uncensoredimage.com/v1" },
});

const res = await llm.invoke("Name three uses for a text API.");
console.log(res.content);

The same rule holds as in Python: the model name has to be set, and the base URL has to end in /v1. If you use the plain OpenAI SDK without LangChain, the options are new OpenAI({ baseURL, apiKey }) and model: "uncensored" in the call.

Streaming, tools and JSON mode through LangChain

Once the name error is gone, the features you are likely to use are supported by the API: streaming with stream: true, tool calling, and JSON mode through response_format. In LangChain you reach them with the usual methods, so streaming looks like this:

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.uncensoredimage.com/v1",
    api_key="YOUR_KEY",
    streaming=True,
)

for chunk in llm.stream("Write two sentences about rain."):
    print(chunk.content, end="", flush=True)

A streamed request holds one of your concurrency slots until the stream finishes. With a full key you have 8 at once and 300 requests per minute; a trial key has 2 and 60. If a LangChain agent fires many parallel calls, you may see HTTP 429 with the code concurrency or rate_limited. Lower the parallelism or add retry with a short delay. When the service is briefly overloaded it also returns 429 with Retry-After: 5.

The context window is 100,000 tokens for prompt plus completion, so long chains that keep appending history will eventually hit it. Trim or summarise old messages. The full parameter list is in the docs.

This is a text-only chat completions service. There are no embeddings, so OpenAIEmbeddings pointed at this base URL will fail, and so will a vector store pipeline that depends on it. Use a separate embedding provider for retrieval and keep this endpoint for the chat step. There is also no image, audio or video generation, despite the word image in the domain name. If you are weighing image options, the site also has a page about the GPT image API.

On cost, you pay per token: $0.15 per 1M input and $0.50 per 1M output, from prepaid credit that never expires. A debugging session that sends 20 small test calls of 200 input and 100 output tokens uses 4,000 input tokens ($0.0006) and 2,000 output tokens ($0.001), so $0.0016 in total. Failed or refused requests are not charged. The pricing page lists top-ups, which on this site are crypto only (USDT on TRC20 or USDC on Base). New users can claim $0.50 of trial credit on the key page, valid for 7 days.

Questions and answers

What model name should I use in LangChain?

Use uncensored. It is the only model ID on this endpoint, and you can confirm it with GET /v1/models.

Do I put /v1 in the base URL?

Yes. The base URL is https://api.uncensoredimage.com/v1, and the client adds /chat/completions itself.

Can I use OpenAIEmbeddings with this endpoint?

No. The service offers chat completions and a models list only, with no embeddings. Use another provider for embeddings.

Why do I get 429 errors from an agent?

Agents can send many requests at once. A full key allows 8 concurrent and 300 per minute, so reduce parallel calls and retry after a short delay.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key