Open AI API Documentation Python: Setup With Base URL
You do not need a special client. The standard OpenAI Python package works against this API once you change two values, and this page walks through every call you are likely to need.

The short version
If you searched for open ai api documentation python, you probably want the shortest path from a blank file to a working call. The official OpenAI Python package is an OpenAI-compatible client, so it will talk to any server that follows the same request format. Here the only differences are the base URL, your key, and the model name.
pip install --upgrade openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.whisperapi.top/v1",
api_key=os.environ["WHISPER_API_KEY"],
)
resp = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You are a concise writing assistant."},
{"role": "user", "content": "Give me three titles for a podcast about night trains."},
],
)
print(resp.choices[0].message.content)
That is the whole integration. Under the hood the SDK sends POST /v1/chat/completions with an Authorization: Bearer header. The model ID is uncensored, and the other method the server supports is GET /v1/models, which returns the list of available models.
Get a key and store it safely
Create an account with Google, or with email and password, then open the API key page. New accounts can claim $0.50 of trial credit with one click there. It needs no card and is valid for 7 days. If you want the details, get an API key walks through the page.
Keep the key out of your source code. Export it as an environment variable and read it in Python, as in the example above:
export WHISPER_API_KEY="paste-your-key-here"
python app.py
Do not commit the key, and do not ship it in browser JavaScript, where anyone can read it. If you build a web product, call the API from your server and expose your own endpoint to the front end.
The OpenAI SDK also reads OPENAI_API_KEY and OPENAI_BASE_URL from the environment when you create OpenAI() with no arguments. That is handy when a tool you did not write builds the client for you: set those two variables to your key and https://api.whisperapi.top/v1, and the tool talks to this API without a code change.
To confirm the connection before writing anything bigger, list the models:
from openai import OpenAI
client = OpenAI(base_url="https://api.whisperapi.top/v1", api_key="YOUR_API_KEY")
for m in client.models.list():
print(m.id) # includes: uncensoredParameters that are passed through
The chat call accepts the parameters you already know. temperature, top_p, stop, seed and the frequency and presence penalties are passed to the model. max_tokens is optional: the completion can use whatever is left of the 100,000-token context window after your prompt, so set it only when you want a hard cap on length, and therefore on cost.
from openai import OpenAI
client = OpenAI(base_url="https://api.whisperapi.top/v1", api_key="YOUR_API_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Write a four-line poem about a lighthouse."}],
temperature=0.8,
top_p=0.95,
max_tokens=200,
seed=42,
stop=["\n\n"],
)
print(resp.choices[0].message.content)
print(resp.usage)
Settings interact, so change one at a time when you tune a prompt. Temperature and top_p both widen or narrow the range of words the model considers, and adjusting both at once makes it hard to tell which one helped. The penalties discourage repeated words and phrases; they are useful for long stories where the model starts to loop, and harmful for structured output where repetition is expected, such as JSON keys. Add a stop sequence when you want to cut generation at a known marker, which also saves output tokens.
A few habits that save trouble. Use a low temperature (0.2 or less) for extraction and classification, and a higher one for fiction. Treat seed as a way to make runs more repeatable, not as a guarantee. And keep the conversation history you send under control: you are billed for the whole prompt on every call, at $0.15 per 1M input tokens, so a long chat gets cheaper to trim than to carry. The pricing page has the full rate card.
Streaming responses
For anything a person watches, stream. Pass stream=True and iterate over the chunks. The server sends them as server-sent events, and the SDK parses them for you.
from openai import OpenAI
client = OpenAI(base_url="https://api.whisperapi.top/v1", api_key="YOUR_API_KEY")
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell a short story about a lost umbrella."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if getattr(chunk, "usage", None):
print("\n", chunk.usage)
Usage is reported at the end of the stream, so the last chunk is where to read token counts. One detail matters for capacity planning: a streamed request holds its concurrency slot until the stream finishes. If a user closes the tab and your code keeps reading, that slot stays busy. Close the stream when the client disconnects.
JSON mode and tool calling
For machine-readable output, ask for JSON mode and say in the prompt that you want JSON. The word "JSON" in the instructions helps the model comply.
import json
from openai import OpenAI
client = OpenAI(base_url="https://api.whisperapi.top/v1", api_key="YOUR_API_KEY")
resp = client.chat.completions.create(
model="uncensored",
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "Reply with a JSON object only."},
{"role": "user", "content": "Extract name and city: 'Maria lives in Porto.'"},
],
)
data = json.loads(resp.choices[0].message.content)
print(data)
Tool calling follows the usual loop: you describe functions in tools, the model replies with tool_calls, you run them, and you send the results back as messages with role: "tool".
import json
from openai import OpenAI
client = OpenAI(base_url="https://api.whisperapi.top/v1", api_key="YOUR_API_KEY")
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current temperature for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "How warm is it in Lisbon?"}]
first = client.chat.completions.create(
model="uncensored", messages=messages, tools=tools, tool_choice="auto"
)
msg = first.choices[0].message
if msg.tool_calls:
messages.append(msg)
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
result = {"city": args["city"], "temp_c": 21} # your real lookup goes here
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(result),
})
final = client.chat.completions.create(model="uncensored", messages=messages, tools=tools)
print(final.choices[0].message.content)
else:
print(msg.content)
Validate the arguments before you act on them. The model can produce a malformed or unexpected value, and a tool that deletes things should never trust it blindly.
Rate limits, errors and retries
A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent and 60 per minute. The maximum body size is 8 MB. Go over a limit and you get HTTP 429 with an error code of rate_limited (too many requests per minute) or concurrency (too many at once). When the service is briefly overloaded it also answers 429, with a Retry-After: 5 header.
The OpenAI SDK retries 429 responses on its own, twice by default, with a short backoff. Raise that number if you run batch jobs:
import asyncio
from openai import AsyncOpenAI, RateLimitError
client = AsyncOpenAI(
base_url="https://api.whisperapi.top/v1",
api_key="YOUR_API_KEY",
max_retries=5,
timeout=120,
)
gate = asyncio.Semaphore(8) # match the concurrency limit of a full key
async def ask(prompt):
async with gate:
try:
r = await client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": prompt}],
)
return r.choices[0].message.content
except RateLimitError as e:
print("still limited:", e.response.headers.get("Retry-After"))
raise
async def main():
prompts = [f"Write a slogan for product {i}." for i in range(40)]
results = await asyncio.gather(*(ask(p) for p in prompts))
print(len(results), "done")
asyncio.run(main())
The semaphore is the important part. It keeps you at 8 requests in flight, so you rarely meet the concurrency error at all. If you do hit rate_limited, you are sending more than 300 requests a minute and need to pace the loop. Every response carries X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency headers, and you can read them with with_raw_response. Log the request ID when you contact support, since it lets someone find the exact call.
Requests that fail or are refused are not charged, so a retry loop does not drain your balance on errors.
Checking the same call outside Python
When something misbehaves, reproduce it without your application code. A raw request removes the SDK, your wrapper and your framework from the list of suspects. If curl works and your Python does not, the bug is on your side. If curl fails too, look at the key, the URL and the account balance.
curl https://api.whisperapi.top/v1/chat/completions -H "Authorization: Bearer $WHISPER_API_KEY" -H "Content-Type: application/json" -d '{"model": "uncensored", "messages": [{"role": "user", "content": "Say hello in three languages."}]}'
The same package exists for Node, which is useful if part of your stack is JavaScript. The options are named slightly differently, but the idea is identical:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.whisperapi.top/v1",
apiKey: process.env.WHISPER_API_KEY,
});
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Say hello in three languages." }],
});
console.log(resp.choices[0].message.content);
Frameworks that wrap the SDK usually expose the same two settings under names such as base URL and API key. Look for an option labelled OpenAI-compatible or custom endpoint, paste the base URL, and type uncensored as the model name. Some tools validate the model name against a built-in list; if yours does, pick the custom or other option so it passes the string through unchanged.
A practical tip for longer projects: keep the base URL, key name and model ID in one configuration module. When you later want to compare this API with another OpenAI-compatible service on your own prompts, you change one file and rerun your test set instead of hunting through the code for hard-coded values.
Common mistakes and where to look next
- Wrong base URL. It must end in
/v1. Without it you get a 404, because the SDK appends/chat/completionsto whatever you pass. - Wrong model name. Use
uncensored. Model names from other vendors are not valid here, and this API is not a router to other vendors. - Features that do not exist. This is a text API. Image generation, audio, embeddings and fine-tuning calls will fail.
- Oversized prompts. Prompt plus completion must fit in 100,000 tokens, and the request body must stay under 8 MB.
- Key in the wrong place. A 401 almost always means a missing, mistyped or revoked key, or a stray space in the environment variable.
For the full list of supported fields, see the site's API documentation. If your use case is generating narration or voice-over text, the text to speech scripts page shows how that fits into a pipeline. Prompts you send are not used for training.
More guides
Questions and answers
Do I need a special Python library?
No. The standard openai package works. Set base_url to https://api.whisperapi.top/v1, pass your key, and use the model ID uncensored.
Does the Python SDK support streaming here?
Yes. Pass stream=True and iterate over the chunks. Usage is sent at the end of the stream, and the request holds its concurrency slot until the stream ends.
Can I use LangChain or other libraries?
Any library that lets you set an OpenAI-compatible base URL and key should work. Point it at the same base URL and use uncensored as the model name.
What happens when I hit a rate limit?
The API returns HTTP 429 with the code rate_limited or concurrency, or a Retry-After: 5 header when briefly overloaded. The SDK retries 429s automatically, and you can raise max_retries.
How much does a test cost?
A request with 2,000 input and 500 output tokens costs $0.00055, so the $0.50 trial credit covers about 900 of them.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.
Get API key