To use an OpenAI-compatible uncensored endpoint with the official OpenAI SDKs, set two values: the base URL (for example https://chainless.one/v1) and the API key, either in code or through the OPENAI_BASE_URL and OPENAI_API_KEY environment variables. Then call chat.completions.create, not responses.create, because most compatible providers implement Chat Completions only. Everything else, including streaming and tool calls, works the same way it does against OpenAI.
What "OpenAI-compatible" means in practice
A provider is OpenAI-compatible when it accepts the same HTTP requests as OpenAI for a subset of endpoints and returns responses in the same shape. The subset varies. Almost every provider implements POST /v1/chat/completions and GET /v1/models. Fewer implement embeddings, images, audio or the newer Responses API.
That subset is the first thing to check before you write code. For the worked example in this article, the API reference lists exactly two endpoints: GET /v1/models and POST /v1/chat/completions, with server-sent events when "stream": true and tool calls on every model. There is no /v1/responses, no embeddings and no images endpoint. Any SDK call outside that set will fail with an HTTP error, which is expected.
Configure the SDK
With environment variables
Both official SDKs read the key and the base URL from the environment. The Python SDK README notes the OPENAI_BASE_URL variable as an alternative to passing base_url, and the client source reads OPENAI_BASE_URL when no base URL is given. The Node SDK client source documents baseURL as defaulting to process.env['OPENAI_BASE_URL'], with https://api.openai.com/v1 as the fallback.
export OPENAI_BASE_URL="https://chainless.one/v1" export OPENAI_API_KEY="$CHAINLESS_API_KEY" This is the least invasive option for an existing app: no code changes, and switching back is a matter of unsetting two variables. The downside is that every OpenAI client in the process now talks to the new endpoint. If your app uses OpenAI for one task and another provider for something else, configure clients explicitly.
In code
Python:
import os from openai import OpenAI client = OpenAI( base_url="https://chainless.one/v1", api_key=os.environ["CHAINLESS_API_KEY"], ) Node:
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://chainless.one/v1", apiKey: process.env.CHAINLESS_API_KEY, }); Note the spelling: base_url in Python, baseURL in Node. The Node option is not baseUrl.
List the models the endpoint serves
Model ids are provider-specific. Do not guess them; ask the endpoint. The list call is also the quickest way to confirm that the base URL and key work.
for model in client.models.list(): print(model.id) for await (const model of client.models.list()) { console.log(model.id); } Against the example endpoint, the response is a standard list object: {"object": "list", "data": [...]}, where each item carries id, object: "model" and owned_by. Some providers add extra fields such as a display name or a context length. The SDKs keep unknown fields on the object, so you can read them, but typed code will not know about them.
Use the ids exactly as returned. A model id with a typo is the single most common reason for a 404 after switching providers. The current ids and their context and output limits are on the models page.
Send a request and stream it
A plain request looks the same as it does against OpenAI:
resp = client.chat.completions.create( model="deepseek-v4.1-uncensored", messages=[{"role": "user", "content": "Explain what a race condition is in two sentences."}], ) print(resp.choices[0].message.content) Streaming adds stream=True and returns an iterator of chunks. Each chunk has a choices list whose delta carries the new piece of text:
stream = client.chat.completions.create( model="glm-5.3-fast-uncensored", messages=[{"role": "user", "content": "Write a haiku about log files."}], stream=True, stream_options={"include_usage": True}, ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) if chunk.usage: print("\n", chunk.usage) The if chunk.choices guard is not decoration. The Chat Completions reference says that with include_usage the stream ends with an extra chunk whose choices array is empty and whose usage field holds the totals. Code that does chunk.choices[0] unconditionally will raise an IndexError on that last chunk.
The Node version:
const stream = await client.chat.completions.create({ model: "glm-5.3-fast-uncensored", messages: [{ role: "user", content: "Write a haiku about log files." }], stream: true, }); for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? ""); } What usually breaks
The SDK examples now use the Responses API
Both official READMEs now present the Responses API as the primary interface and describe Chat Completions as the previous standard, supported indefinitely. If you copy the first example from the README, you get client.responses.create(...). A provider without /v1/responses answers that with a 404, which looks like a bad URL but is really an unsupported endpoint. Use client.chat.completions.create instead.
The same trap exists one layer up. The Vercel AI SDK OpenAI provider docs say the default openai('model-id') factory uses the Responses API, and that you should create models with openai.chat('model-id') when your custom base URL only supports Chat Completions. Other frameworks have similar switches. Check which endpoint your wrapper calls before blaming the provider.
The base URL is one level off
The SDKs append paths such as /chat/completions to the base URL. So the base URL must end at the version segment:
| Base URL you set | Request goes to | Result |
|---|---|---|
https://chainless.one/v1 | /v1/chat/completions | works |
https://chainless.one | /chat/completions | 404 |
https://chainless.one/v1/chat/completions | /v1/chat/completions/chat/completions | 404 |
Parameters the provider ignores or rejects
Compatible does not mean identical. Some providers ignore parameters they do not implement, others reject them with a 400. Typical candidates are logprobs, n greater than one, seed, and OpenAI-specific fields like service_tier. If a request that worked against OpenAI fails with a 400 after the switch, remove optional parameters one by one until it passes.
Retries hide the real error
Both SDKs retry some failures by default: the READMEs list connection errors, 408, 409, 429 and 5xx, retried twice with a short backoff. That is reasonable in production, but while you are setting things up, it can turn a quick 429 into a long pause. Set max_retries=0 (Python) or maxRetries: 0 (Node) during debugging so errors surface immediately.
Typed responses and extra fields
Models that reason may return extra fields in the message or the streaming delta that the OpenAI types do not declare. The SDKs keep them on the object, but a strict type checker or a schema validator in your own code may complain. Read them defensively, and do not assume they exist on every provider.
Once a single request and a streamed request both work, the rest of the app usually follows with no further changes. The API reference linked above has curl versions of each call, which are useful for checking whether a failure comes from the SDK setup or from the request itself.