Short answer: two different routes
If your question is literally using Gemini with LangChain, the usual path is Google's integration package, which has its own chat class and reads a Google API key. That package talks to Google's models and nobody else's. Check Google's and LangChain's current documentation for the exact class names and options, because both projects change their interfaces from time to time.
This site offers something else. It is a hosted, OpenAI-compatible text API running one open-weight model that is tuned to answer without content refusals for lawful adult use. It is not Gemini, it is not made by Google, and it is not a router that forwards your calls to Google. What it shares with Gemini setups is the workflow: you build chains and agents in LangChain, and the model behind them is one constructor away from being swapped.
Because the API speaks the OpenAI protocol, LangChain needs no special adapter. The standard ChatOpenAI class from langchain-openai works once you change the base URL, the key and the model name. Everything else in your project, prompts, parsers, retrievers, tools, stays as it is.
| Setting | Value |
|---|---|
| Class | ChatOpenAI from langchain_openai |
| base_url | https://api.uncensoredgemini.top/v1 |
| model | uncensored |
| api_key | your key, sent as a Bearer token |
Install and make the first call
Install the integration package with pip install langchain-openai langchain-core. If you do not have a key yet, the API key page explains sign-up, and new accounts can claim $0.50 of trial credit there with one click, no payment needed. The trial key is valid for 7 days.
Store the key in an environment variable rather than in the source file. Then create the model object:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.uncensoredgemini.top/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
temperature=0.7,
)
reply = llm.invoke("Give me three names for a fantasy tavern.")
print(reply.content)
That is the whole migration for a simple script. If your code previously built a Gemini chat object, replace that one line and keep the rest. Calls like invoke, stream, batch and the pipe operator behave the same way, because they belong to LangChain's shared runnable interface and not to any one provider.
Two details trip people up. First, the base URL must end in /v1, since LangChain appends /chat/completions to it. Second, the model name is a plain string and the server only knows uncensored, so a leftover Gemini model name will produce an error. You can confirm what the server offers with a GET /v1/models call.
Streaming tokens to the user
Streaming uses server-sent events on the API side, and LangChain exposes it as an iterator. Each chunk carries a small piece of text in content.
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.uncensoredgemini.top/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
for chunk in llm.stream("Write a two-paragraph scene set on a night train."):
print(chunk.content, end="", flush=True)
print()
One operational detail matters here. A streamed request holds its concurrency slot until the stream finishes, so a client that opens a stream and never reads it to the end keeps a slot occupied. A full key allows 8 concurrent requests, a trial key allows 2. If you serve many users from one key, put a small queue or semaphore in front of the model.
Tool calling with bind_tools
The endpoint supports tools, tool_choice, streamed tool_calls and tool results sent back with role: "tool". In LangChain you declare a tool with the @tool decorator and attach it with bind_tools. The loop below runs one tool call by hand, which is the clearest way to see what an agent framework does for you.
import os
from langchain_core.messages import HumanMessage, ToolMessage
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
@tool
def order_status(order_id: str) -> str:
"""Return the shipping status for an order id."""
return "Order " + order_id + " left the warehouse on Monday."
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.uncensoredgemini.top/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
llm_tools = llm.bind_tools([order_status])
messages = [HumanMessage("Where is order A-1042?")]
ai = llm_tools.invoke(messages)
messages.append(ai)
for call in ai.tool_calls:
result = order_status.invoke(call["args"])
messages.append(ToolMessage(content=result, tool_call_id=call["id"]))
final = llm_tools.invoke(messages)
print(final.content)
If the model answers without calling the tool, tighten the tool description and the system message, or pass tool_choice through bind_tools to force a call. Open-weight models differ in how eagerly they use tools, so test with your real schemas and a few awkward prompts before you build a long agent on top.
JSON output and a small chain
JSON mode is available through response_format. In LangChain you can attach it with bind. Keep the word JSON in your prompt and describe the keys you want, because JSON mode guarantees valid syntax and not your particular schema.
import json
import os
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.uncensoredgemini.top/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
temperature=0,
)
prompt = ChatPromptTemplate.from_messages([
("system", "Reply with a JSON object with keys title and tags (a list of strings)."),
("human", "Describe this story idea: {idea}"),
])
chain = prompt | llm.bind(response_format={"type": "json_object"}) | StrOutputParser()
data = json.loads(chain.invoke({"idea": "a lighthouse keeper who can hear ships"}))
print(data["title"], data["tags"])
Always wrap json.loads in a try block in production code, and retry once on failure. A response cut short by a stop sequence or a client timeout can leave the object incomplete.
Keeping the provider swappable
Teams that try several models usually stop hard-coding the class. A small factory function reads the choice from the environment, so the same chain runs against whichever backend you configure. The branch for this endpoint is shown below; the other branch would construct whatever class your other provider needs.
import os
from langchain_openai import ChatOpenAI
def make_llm(temperature=0.7):
# One place to change the endpoint for every chain in the project.
return ChatOpenAI(
model=os.environ.get("LLM_MODEL", "uncensored"),
base_url=os.environ.get("LLM_BASE_URL", "https://api.uncensoredgemini.top/v1"),
api_key=os.environ["UNCENSORED_API_KEY"],
temperature=temperature,
)
llm = make_llm(0.3)
print(llm.invoke("Summarise the plot of a heist film in one sentence.").content)
This pattern also makes A/B tests easy. Run the same fifty prompts through two configurations, save both outputs, and compare them side by side before you commit a product to either. Because LangChain chat models share one interface, nothing downstream of the factory needs to know which backend answered.
Errors worth recognising
An authentication error usually means the key was pasted with a trailing space or the variable is unset in the process that runs your code. A not-found error usually means the base URL lacks /v1. A model error means a stale Gemini model name is still in a config file. Each of these shows up on the first call, which is one reason to run a one-line smoke test before wiring up a larger chain.
Batches, retries and cost
LangChain's batch method runs many inputs in parallel. Cap it at the number of concurrent requests your key allows:
- Full key:
config={"max_concurrency": 8}, with a ceiling of 300 requests per minute. - Trial key:
config={"max_concurrency": 2}, with 60 requests per minute.
Going over a limit returns HTTP 429. The error code is rate_limited when you exceed requests per minute and concurrency when too many are in flight. Temporary overload also returns 429 with a Retry-After: 5 header. The max_retries argument of ChatOpenAI handles these automatically through the underlying OpenAI client, so set it to something like 3 and keep the concurrency cap honest.
Pricing is pay as you go from prepaid credit: $0.15 per 1M input tokens and $0.50 per 1M output tokens. A chain call with 1,500 input tokens and 400 output tokens costs 1,500 × $0.15 / 1M = $0.000225 for input plus 400 × $0.50 / 1M = $0.0002 for output, so $0.000425 in total. A thousand such calls cost $0.425. Failed or refused requests are not charged, and credit never expires. The pricing page lists top-up amounts and bonuses, and payment is in crypto (USDT on TRC20 or USDC on Base).
Remember that RAG chains inflate input size. Ten retrieved passages of 500 tokens each add 5,000 input tokens to every call, which costs $0.00075 per call at the input rate. Trim the retriever's k before you worry about anything else.
Where Gemini is still the better fit
Be clear about what you give up. If you need Google's multimodal input, audio or image understanding, or very long context beyond 100,000 tokens, this endpoint will not do that job. It is text only, with a 100,000-token window shared by prompt and completion, and it has no embeddings, image generation or fine-tuning. Embeddings for a vector store have to come from somewhere else, and LangChain lets you mix providers in one pipeline.
The reasons to use this endpoint are narrower: you want a model that does not refuse lawful adult content in fiction, roleplay or companion apps, you want a flat per-token price, and you want to keep OpenAI-style code. Hard limit: no sexual content involving minors, and it cannot be switched off. Prompts are not used for training. For the raw request format behind everything above, read the API docs.
