What you need before you start
Command-line coding agents such as Qwen Code can talk to any server that implements the OpenAI chat completions protocol. This site hosts one: an OpenAI-compatible text API with a single model, ID uncensored. It is an open-weight model run by an independent provider and tuned to answer without content refusals for lawful adult use. It is not the official Qwen service, and it only generates text.
You need:
- An API key from the API key page. Sign in with Google or with email and password. New users can claim $0.50 of trial credit with one click, valid for 7 days and with no card.
- The base URL:
https://api.qwencodeapikey.com/v1 - The model name:
uncensored
Keep the key out of source control. If it ever leaks, reissue it on the same page and the old one stops working at once.
Step 1: test the key with curl
Do this before touching any tool. If curl works, the credentials are fine and any later failure is a configuration problem in the agent.
curl https://api.qwencodeapikey.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Write a Python function that reverses a string."}]
}'
A JSON response with a choices array means success. The response headers include X-Balance-USD, so you can see your remaining credit as you go.
Step 2: set the environment variables
Agents built on the OpenAI client conventions read OPENAI_API_KEY, OPENAI_BASE_URL and OPENAI_MODEL. Variable names and extra settings can differ between versions of a tool, so confirm them in its README or help output. On macOS and Linux:
export OPENAI_API_KEY="YOUR_KEY"
export OPENAI_BASE_URL="https://api.qwencodeapikey.com/v1"
export OPENAI_MODEL="uncensored"
On Windows PowerShell, set them for the current session like this:
$env:OPENAI_API_KEY = "YOUR_KEY"
$env:OPENAI_BASE_URL = "https://api.qwencodeapikey.com/v1"
$env:OPENAI_MODEL = "uncensored"
These last until you close the terminal. To keep them, add the exports to your shell profile, or put them in a .env file if your tool reads one. Restart the terminal after editing a profile file, because running shells do not reread it.
Step 3: run the agent and send a test prompt
Start the tool from a project directory in the same terminal where you set the variables. If it asks you to pick an authentication method on first launch, choose the OpenAI-compatible option if your version offers one (menu labels differ between versions, so check its docs), so that it reads the variables above. Then send a small, checkable task:
Create a file hello.py that prints the first ten Fibonacci numbers, then run it.
A good result is a plausible file and a clean run. That one prompt exercises streaming output and, for tools that edit files, tool calling. This API supports streaming over SSE and OpenAI-style tool calling with tools and tool_choice, which agents depend on. Judge code quality on your own tasks, since it is a single hosted model whose output you should review like any other generated code.
Check tool calling
Coding agents read and write files by asking the model to call functions. The API accepts tools and tool_choice in the OpenAI format and returns tool_calls, so you can check this path with one request:
curl https://api.qwencodeapikey.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "What is in main.py?"}],
"tools": [{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file from the project",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"]
}
}
}]
}'
If the reply contains a tool_calls entry naming read_file, the model chose to call your function, and the agent will send the result back as a message with role: "tool". If it answers in plain text instead, add "tool_choice" to force the call and see whether the agent's own prompts need adjusting.
The same key from code
If you also call the API from scripts, the official OpenAI SDKs need only the two values. Python:
from openai import OpenAI
client = OpenAI(
base_url="https://api.qwencodeapikey.com/v1",
api_key="YOUR_KEY",
)
r = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Explain list comprehensions in two sentences."}],
)
print(r.choices[0].message.content)
Node.js:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.qwencodeapikey.com/v1",
apiKey: process.env.OPENAI_API_KEY,
});
const r = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Explain closures in two sentences." }],
});
console.log(r.choices[0].message.content);What a coding session costs
Agents resend context on every step, so input tokens dominate. Take a session of 40 model calls, each with 20,000 input tokens and 1,000 output tokens:
- Input: 40 x 20,000 = 800,000 tokens x $0.15 per 1M = $0.12
- Output: 40 x 1,000 = 40,000 tokens x $0.50 per 1M = $0.02
- Total: $0.14
The $0.50 trial credit pays for three or four sessions of that size. Prompts sent to the API are not used for training. Keep an eye on X-Balance-USD as you work, and top up when you need more, with any whole amount from $20 to $500 in crypto.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 Unauthorized | Wrong or stale key, or stray whitespace or quotes | Re-copy the key, or reissue it on the key page |
| 404 Not Found | Base URL without /v1, or a doubled path | Use exactly the base URL shown above |
| Model not found | The tool sends a default model name | Set OPENAI_MODEL to uncensored |
| 429 with rate_limited | Over the requests per minute limit | Slow down or batch work |
| 429 with concurrency | Too many requests at once | Cut parallel tool calls to the limit |
| 429 with Retry-After: 5 | Temporary overload | Wait 5 seconds and retry |
Limits depend on the key type. A full key allows 8 concurrent requests and 300 requests per minute, while a trial key allows 2 concurrent and 60 per minute. Agents that fan out many parallel calls hit the concurrency cap first. A streamed request holds its slot until the stream ends.
Request bodies are capped at 8 MB and the context window is 100,000 tokens. A coding agent that pastes whole repositories into the prompt can reach that, so point it at the files you need. Cost stays modest: input is $0.15 per 1M tokens and output $0.50 per 1M. The docs and pricing page have the details, and the production checklist for API keys covers rotation and storage habits worth adopting.
