EN ▾
Get API key

LangChain Free API Key: Setup for an OpenAI-Style API

You can try LangChain against a hosted uncensored model without paying first. Claim the trial credit, change the base URL in ChatOpenAI, and your existing chains keep working.

Updated

Chain of linked blocks flowing from a terminal to a key, illustrating a LangChain API key setup

Key points

  • The trial is $0.50 of credit, claimed with one click on the key page, valid for 7 days. It is a trial, not a permanent free tier.
  • LangChain needs only three changes: base_url, api_key and model name <code>uncensored</code>.
  • Streaming, tool calling and JSON mode are supported, so agents and structured output work.
  • There are no embeddings on this API, so a RAG pipeline needs a separate embedding source.

What a free key means here

Searching for a langchain free api key usually ends in one of two places: a vendor with a small free tier that rate-limits you into the ground, or a forum post pointing at a key that stopped working last month. The honest version of the answer for this service is short. There is no permanent free plan. There is a trial: after you sign up, the API key page has a button that adds $0.50 of credit to your account. It takes one click, it needs no payment, it is limited to one claim per person, and it expires after 7 days.

That sounds small, and it is, but the price makes it go further than you would expect. Input costs $0.15 per 1M tokens and output costs $0.50 per 1M tokens. A typical LangChain test call with a 1,500-token prompt and a 400-token answer costs 1,500 x $0.15 / 1,000,000 = $0.000225 for input plus 400 x $0.50 / 1,000,000 = $0.0002 for output, so $0.000425 in total. Half a dollar covers a little over 1,100 of those calls, which is plenty for building and debugging a chain.

Sign-up works with Google, or with email and password. The trial key has tighter limits than a funded key: 2 concurrent requests and 60 requests per minute, against 8 and 300 for a full key. Keep that in mind when you run batches, and see the section on concurrency below.

The model behind the endpoint is one open-weight model run by an independent provider. It is tuned to answer without content refusals for lawful adult use. It is not the official API of any model vendor and it is not a router. You always talk to the same model, and its ID is uncensored.

Get the key and check it works

Open the API key page, sign in, create a key and press the trial button. Copy the key somewhere safe, then export it so that your code never contains it:

export UNFILTERED_API_KEY="paste-your-key-here"

Before you touch LangChain, confirm that the key and the endpoint agree with each other. The API supports GET /v1/models, which is the cheapest possible check:

curl https://api.unfilteredimagegenerator.top/v1/models \
  -H "Authorization: Bearer $UNFILTERED_API_KEY"

If this returns a JSON list that includes uncensored, the key is good. A 401 means the key was pasted wrongly or has a stray space or newline in it. Fix that here, because LangChain's error messages for auth problems are longer and harder to read than curl's.

The full request format, parameters and error codes are in the API documentation. This article only covers the LangChain side.

Point ChatOpenAI at the base URL

The API speaks the OpenAI chat completions protocol, so LangChain's OpenAI integration is the right class. You do not need a custom wrapper. Install the package and write the smallest working call:

pip install langchain-openai langchain-core
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.unfilteredimagegenerator.top/v1",
    api_key=os.environ["UNFILTERED_API_KEY"],
    temperature=0.7,
)

reply = llm.invoke("Write two sentences about a lighthouse keeper who hates the sea.")
print(reply.content)

Three arguments do all the work. base_url redirects the client away from the default OpenAI host. api_key becomes the Bearer token. model must be uncensored, because that is the only model ID the endpoint serves. If you pass a different name, expect an error rather than a silent fallback.

The same thing in Node, with the JavaScript package:

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

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

const reply = await llm.invoke("Name three plot twists for a heist story.");
console.log(reply.content);

One pitfall catches people who already have OpenAI variables in their shell. If OPENAI_API_KEY or OPENAI_BASE_URL are set globally, a half-configured client may pick them up and send your real OpenAI key to the wrong host, or the wrong key to this one. Pass the values explicitly as shown above and the environment cannot interfere.

Chains, prompts and streaming

Once the model object exists, everything above it in LangChain works as usual. A prompt template piped into the model and an output parser is the standard shape:

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a blunt editor. Reply in plain prose, no lists."),
    ("human", "Critique this opening line: {line}"),
])

chain = prompt | llm | StrOutputParser()
print(chain.invoke({"line": "It was a dark night and the rain fell down."}))

Streaming goes over server-sent events. In LangChain you call .stream() and iterate:

for chunk in chain.stream({"line": "The door was open, which was wrong."}):
    print(chunk, end="", flush=True)

Remember that a streamed request holds its concurrency slot until the stream ends. On the trial key you have two slots, so a UI that starts a stream, abandons it without closing, and starts another can run out of slots surprisingly fast. Close the generator when the user navigates away.

System prompts

Because this model is tuned to answer without content refusals, you do not need long jailbreak-style preambles in the system message. Keep the system prompt about the job: tone, format, persona, and the boundaries of your own application. Short prompts also cost less, since every system token is billed as input on every call.

Tool calling and JSON mode

Agents depend on tool calling, and the endpoint supports tools, tool_choice, streamed tool_calls and tool results sent back as role: "tool" messages. LangChain hides that behind bind_tools:

from langchain_core.tools import tool

@tool
def word_count(text: str) -> int:
    'Count the words in a piece of text.'
    return len(text.split())

llm_tools = llm.bind_tools([word_count])
msg = llm_tools.invoke("How many words are in: the quick brown fox?")
print(msg.tool_calls)

The returned message carries a tool_calls list with the function name and arguments. To finish the loop, run the tool yourself, append a ToolMessage with the result, and call the model again. LangGraph's prebuilt agents do this for you and work with the same ChatOpenAI object.

For structured output you have JSON mode. Ask for it through the model's bind method, and say the word JSON in the prompt so the model knows what shape to produce:

json_llm = llm.bind(response_format={"type": "json_object"})
out = json_llm.invoke(
    "Return a JSON object with keys title and tags (a list of 3 strings) for a story about a stolen map."
)
print(out.content)

Parse the result with json.loads and still handle failures. JSON mode makes valid JSON far more likely, but a response cut off by a stop sequence or a very small max_tokens can still be broken. Wrap the parse in a try block and retry once.

Batches, retries and the 429 problem

LangChain makes parallel work easy, which is exactly how people hit rate limits. The limits are explicit: a full key allows 8 concurrent requests and 300 requests per minute; the trial key allows 2 and 60. Going over returns HTTP 429. The error code tells you which limit you hit: rate_limited means too many requests per minute, concurrency means too many at once. A temporary overload also returns 429, with a Retry-After: 5 header.

Cap the parallelism in the call and let the client retry:

llm = ChatOpenAI(
    model="uncensored",
    base_url="https://api.unfilteredimagegenerator.top/v1",
    api_key=os.environ["UNFILTERED_API_KEY"],
    max_retries=4,
    timeout=120,
)

questions = [f"Give one name for character number {i}." for i in range(20)]
answers = llm.batch(questions, config={"max_concurrency": 2})

With max_concurrency set to 2 you stay inside the trial limit. After you add credit, raise it to 6 or 7 and leave one slot spare for interactive traffic. The response headers help with monitoring: X-Balance-USD shows what is left, and the two X-RateLimit headers show your limits. Failed or refused requests are not charged, so a retry after a 429 costs nothing extra.

What does not work, and what to do about it

Two limits matter for LangChain projects. First, the API is text only. There is no image, audio or video generation. The site name mentions images, but this endpoint serves language model text, so an image chain needs a different provider for the picture step. Second, there are no embeddings and no fine-tuning. A retrieval-augmented pipeline built on VectorStore classes needs an embedding model from somewhere else; only the generation step would call this API. That split is common and works fine, as long as you plan for it before you wire up the stack.

Context is 100,000 tokens for prompt plus completion together, and max_tokens is optional. For long conversation memory, trim old messages with LangChain's message trimming helpers instead of relying on the window as a dump. You pay for every input token on every call, so a 60,000-token history sent for each turn costs 60,000 x $0.15 / 1,000,000 = $0.009 per call before the answer.

The content rule is simple. The model is tuned for lawful adult use and there is a hard limit: no sexual content involving minors. Your application should enforce its own policies on top.

Moving from the trial to a funded key

When the $0.50 is used up, you top up with any whole amount from $20 to $500. Bonuses apply on larger amounts: +5% from $50, +10% from $100 and +15% from $200. Payment is in crypto, USDT on TRC20 or USDC on Base. Credit is prepaid, there is no subscription, and it never expires, so you can top up once and use it over months. The pricing page lists the current terms.

A funded key lifts the limits to 8 concurrent requests and 300 per minute. Nothing in your LangChain code changes except the key value. That is the real advantage of an OpenAI-compatible endpoint: moving a prototype from trial to production is an environment variable.

Prompts are not used for training, which matters if your chains process private drafts. Read the documentation for details on parameters such as seed, stop and the penalty settings, which are passed through to the model.

Questions and answers

Is there a permanent free tier?

No. New users can claim $0.50 of trial credit with one click on the API key page. It is valid for 7 days, one claim per person.

Which LangChain class should I use?

Use ChatOpenAI from langchain-openai (or @langchain/openai in Node) with a custom base URL, your key, and the model name uncensored.

Can I use LangChain agents and tools?

Yes. Tool calling is supported, including streamed tool calls, so bind_tools and LangGraph agents work with the same ChatOpenAI object.

Can I build a RAG app with it?

For the generation step, yes. The API has no embeddings endpoint, so you need a separate source of embeddings for the retrieval step.

Your key is one form away

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

Get API key