Qwen API Integration: LangChain, SillyTavern, Cursor
Every tool that speaks the OpenAI protocol can talk to this API after three settings change. Below are the exact values and the steps for LangChain, SillyTavern, Cursor and a plain SDK with tool calls.
Updated
Key points
- Three values drive every integration: base URL https://api.qwenapi.top/v1, your Bearer key, and the model ID uncensored.
- LangChain needs only ChatOpenAI with base_url and model set; tools and JSON mode pass through.
- SillyTavern uses its custom OpenAI-compatible source; Cursor uses its OpenAI base URL override.
- Plan around 8 concurrent requests and 300 requests per minute on a full key.

What an integration needs
A qwen api integration here is simpler than the name suggests, because there is no vendor-specific SDK to install. The service speaks the OpenAI chat protocol, so anything that already supports a custom OpenAI endpoint is a candidate. You supply the base URL https://api.qwenapi.top/v1, a key from the API key page sent as Authorization: Bearer, and the model name uncensored.
It helps to be clear about what sits behind that endpoint. It is one open-weight model run by an independent provider and tuned to answer without content refusals for lawful adult use. It is text only. It does not offer embeddings, images, audio or fine-tuning, so any framework feature that depends on those needs a different source. It is also not the official service of a model vendor, which matters when a tool shows a vendor logo and assumes vendor behaviour. If you want background on how this fits with the Qwen family of open models, the integration guide covers it.
Before wiring anything into a framework, do one raw check so you know the credentials work. The fastest is GET /v1/models with your key. If that returns a list containing uncensored, every failure after this point is a tool setting, not an account problem.
LangChain in Python
LangChain's OpenAI chat class accepts a custom base URL, so the whole integration is one constructor call. Install langchain-openai and set the key in your environment.
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="uncensored",
base_url="https://api.qwenapi.top/v1",
api_key=os.environ["QWENAPI_KEY"],
temperature=0.7,
timeout=120,
)
print(llm.invoke("Give me three names for a fantasy tavern.").content)
Streaming works through the usual iterator. Remember that each open stream occupies one of your concurrency slots until it finishes, so close or exhaust every generator.
for chunk in llm.stream("Describe a harbour town at dawn in four sentences."):
print(chunk.content, end="", flush=True)
# base_url="https://api.qwenapi.top/v1", model="uncensored" as set above
Tools and structured output
Tool calling and JSON mode are both supported by the API, and LangChain forwards them. Use bind_tools for functions and bind with a response format for JSON.
from langchain_core.tools import tool
@tool
def roll_dice(sides: int) -> int:
# Roll a die with the given number of sides.
import random
return random.randint(1, sides)
# llm was created above with base_url="https://api.qwenapi.top/v1" and model="uncensored"
with_tools = llm.bind_tools([roll_dice])
msg = with_tools.invoke("Roll a twenty-sided die for me.")
print(msg.tool_calls)
json_llm = llm.bind(response_format={"type": "json_object"})
print(json_llm.invoke("Reply with a JSON object with keys name and class.").content)
When you ask for JSON mode, also say "JSON" in the prompt itself. The mode constrains the output format, and an explicit instruction keeps the content on target. Validate what comes back with your own schema check, since no format switch guarantees every field you want.
In LangChain.js the same settings sit under a configuration object: new ChatOpenAI({ model: "uncensored", apiKey, configuration: { baseURL: "https://api.qwenapi.top/v1" } }).
SillyTavern
SillyTavern is a front end for roleplay, fiction and companion chats, and it can connect to any OpenAI-compatible endpoint. That makes it a natural fit for a model that does not refuse adult fiction, as long as everything stays within lawful adult use. The hard limit is the same everywhere: no sexual content involving minors.
- Open the plug icon (API connections) and set the API type to Chat Completion.
- Choose the custom OpenAI-compatible source from the chat completion source list.
- In the custom endpoint field, enter
https://api.qwenapi.top/v1. - Paste your key into the key field and save it.
- In the model field, type
uncensored. If the app offers a model list pulled from the server, the same ID appears there. - Press connect. A green status means the app could reach the server and read the model.
Then look at two numbers. The context size slider in the app should not exceed what the server allows, which is 100,000 tokens for prompt and reply together. Long character cards and large lore books eat into that budget, so keep the reply length at a sensible cap and let the chat history fill the rest. Second, group chats and background tools such as summaries can fire several requests at once. A full key allows 8 concurrent requests, a trial key allows 2, so the trial can show a 429 with code concurrency in group chats that a full key never hits.
Menu names change between SillyTavern versions. If a label differs from the one above, look for the connection type that says custom or OpenAI-compatible; the three values stay the same.
Cursor and other code editors
Cursor lets you override the OpenAI base URL and add your own model names in its model settings. The steps, as the labels exist today, are to open the settings, find the models section, enable the OpenAI key option, paste your key, switch on the base URL override and enter https://api.qwenapi.top/v1, then add a custom model called uncensored. Editors change these screens often, so check Cursor's own documentation if something has moved.
Expect some limits. Editors tune their best features, such as multi-file edits or inline completion, for specific vendor models and sometimes only enable them on their own backends. A custom endpoint usually still works in chat and in basic edit modes. If a feature is greyed out, that is an editor decision, not a problem with your key. The same applies to other editors and extensions that offer a "custom OpenAI" provider: they all want the same three values, and some ask for the complete chat completions URL rather than the base. For a deeper comparison of coding setups, read the documentation first so you know what the API can and cannot do.
Keep a coding tool's request pattern in mind. Editors often send a large slice of your repository as context on every message. At $0.15 per million input tokens that is cheap per call, but a 60,000-token prompt sent 100 times is 6,000,000 input tokens, or $0.90. It is worth watching the X-Balance-USD header while you test.
A plain SDK loop with tool calls
If you are building your own agent rather than using a framework, the raw SDK is only a few lines more. This example defines one tool, lets the model call it, runs it, and sends the result back as a role: "tool" message.
import json, os
from openai import OpenAI
client = OpenAI(base_url="https://api.qwenapi.top/v1", api_key=os.environ["QWENAPI_KEY"])
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Lisbon?"}]
first = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
messages.append(first.choices[0].message)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps({"city": "Lisbon", "temp_c": 21}),
})
final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)
In production, check that tool_calls is present before indexing it, and parse the arguments string with a try block, because a model can occasionally emit malformed JSON for arguments. A short retry with the error message appended usually fixes it.
Smoke-testing the integration before you ship
A framework hides a lot of detail, which is useful until something fails. Before you rely on a new setup, run a short smoke test that touches each feature you plan to use: one plain call, one streamed call, one tool call and one JSON-mode call. Each takes seconds and costs a fraction of a cent, since the price is $0.15 per million input tokens and $0.50 per million output tokens.
Log the X-Request-Id response header with every call. If something odd happens in production, that identifier is what lets support find the exact request. Many frameworks hide response headers by default, so look for a raw response option or a callback that exposes them. While you are there, log token usage from the response so you can see cost trends per feature, not only per month.
Finally, write down which settings you changed in each tool, with a screenshot if the tool is a desktop app. Months later, when the app updates and resets a field, you will want to know what the correct values were: the base URL, the model ID uncensored, and which key is stored where. The pricing page and the account balance header are enough to confirm that the key you configured is the one being billed.
Limits to design around
Integration problems after the first success are almost always about volume. A full key permits 8 requests in flight and 300 per minute. The request body can be up to 8 MB. Past a limit the API answers HTTP 429 with the code rate_limited or concurrency, and on temporary overload it adds Retry-After: 5.
- Use a semaphore. In an async app, cap parallel calls at 8 with a semaphore so you queue locally rather than collect 429s.
- Back off on 429. Honour
Retry-Afterwhen present, otherwise wait a few seconds and add jitter. - Pay only for success. Failed or refused requests are not charged, so retries on errors do not add to your bill.
- Trim history. Send only the turns the model needs. The window is 100,000 tokens, and every token you resend is billed as input.
Prompts are not used for training, which is worth knowing when you integrate with tools that log conversations on your side. Check your own tool's logging settings, since those are outside this service. Prices and top-up options are on the pricing page.
More guides
Questions and answers
Which model name do I use in LangChain or Cursor?
Use uncensored. It is the only model ID, and it must match exactly in the model field of whichever tool you use.
Does LangChain tool calling work with this API?
Yes. Tools, tool_choice and streamed tool calls are supported, and results go back as messages with role tool. Use bind_tools in LangChain.
Can I use embeddings with LangChain here?
No. The API offers chat completions and a model list only, with no embeddings endpoint. Use a separate embedding source for retrieval.
Why does SillyTavern show a concurrency error on the trial?
A trial key allows 2 concurrent requests, and group chats can send more at once. A full key allows 8, or you can reduce parallel features.
Is this the official Qwen API?
No. It is an independent provider running one open-weight model under its own keys, so official vendor keys and endpoints do not apply.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.