What a model call really is
Behind every chat window and writing assistant sits the same exchange. Your program posts a JSON body to POST /v1/chat/completions. The body names a model, carries a list of messages, and may include settings. The server replies with a JSON body that holds the generated text and a count of the tokens used.
That is why a single client library covers so many services. If a provider speaks the OpenAI request format, you point the official SDK at its address, give it your key and pick its model name. Here the address is https://api.uncensoredaimodel.com/v1, the key comes from your account, and the model is uncensored. The model is one open-weight text model, run by an independent provider. It handles text only, so for images, audio or embeddings you need other tools.
Before writing code, get a key. A word on tokens, since the pricing and the limits are built on them: a token is a chunk of text, often a short word or a piece of a longer one. The context window of 100,000 tokens covers your prompt and the reply together, so a very long prompt leaves less room for the answer. Sign up with Google or with email and password, open the API key page, and claim the trial: $0.50 of credit in one click, valid for 7 days, with no card.
Your first request
Install the SDK with pip install openai, store the key in an environment variable, and run this.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.uncensoredaimodel.com/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
response = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "You are a patient tutor who explains ideas with short examples."},
{"role": "user", "content": "Explain what a hash map is."},
],
)
print(response.choices[0].message.content)
print(response.usage)Messages carry a role. The system message sets behavior and tone, user messages hold what a person said, and assistant messages hold earlier replies from the model. The generated text lives in choices[0].message.content. The usage object reports how many tokens went in and came out, which is the number your bill is built from.
If you prefer the terminal, the same call works with curl:
curl https://api.uncensoredaimodel.com/v1/chat/completions \
-H "Authorization: Bearer $UNCENSORED_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "uncensored", "messages": [{"role": "user", "content": "Explain what a hash map is."}]}'Settings that change the output
A handful of parameters cover most needs. All of these are passed through to the model.
- temperature controls randomness. Low values (0 to 0.3) give steadier, more repeatable answers, which suits extraction and classification. Values around 0.7 to 1.0 suit fiction and brainstorming.
- top_p limits sampling to the most likely tokens. Change either temperature or top_p, not both at once, so you can tell what each did.
- max_tokens caps the reply length. It is optional here; without it the completion may use the rest of the 100,000-token window, so set it when you want short answers.
- stop ends generation when a given string appears, handy for formats with a clear terminator.
- seed asks for reproducible sampling. Use it while testing prompts so a change in output comes from your edit, not from chance.
- frequency and presence penalties discourage repetition in long generations.
Defaults are fine for a first prototype, so do not tune anything until you have a prompt that mostly works. Change one setting at a time and keep notes. Prompt work is closer to experimenting than to programming, and unrecorded changes are the usual reason people cannot reproduce a good result.
Conversation state is your job
The API remembers nothing between calls. A chat only feels continuous because your code resends the earlier messages every time. Keep a list, append each new user message, send the whole list, then append the reply.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.uncensoredaimodel.com/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
messages = [{"role": "system", "content": "You are a friendly cooking coach."}]
while True:
text = input("you> ")
if text.strip().lower() == "quit":
break
messages.append({"role": "user", "content": text})
r = client.chat.completions.create(model="uncensored", messages=messages)
answer = r.choices[0].message.content
messages.append({"role": "assistant", "content": answer})
print("bot>", answer)This has a cost consequence. Input tokens are billed at $0.15 per million, and the history counts as input on every turn. Say each exchange adds about 500 tokens. Turn k then sends roughly 500 × k input tokens, so a 20-turn chat sends 500 × (1 + 2 + … + 20) = 105,000 input tokens in total, which costs about $0.016 at that rate. The last turn alone carries about 10,000 tokens. That is small for one user, but it adds up across thousands of users. When histories grow long, keep the system message and the most recent turns, and replace the middle with a short summary.
Get structured output with JSON mode
Free-form text is awkward to feed into other code. Setting response_format to {"type": "json_object"} makes the reply valid JSON. It does not enforce a schema, so describe the keys you want in the prompt and validate the result.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.uncensoredaimodel.com/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
r = client.chat.completions.create(
model="uncensored",
temperature=0.2,
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": "Reply only with JSON."},
{"role": "user", "content": "Extract name, city and age from: Maria, 34, lives in Porto. Keys: name, city, age."},
],
)
person = json.loads(r.choices[0].message.content)
print(person["name"], person["city"], person["age"])Models can still return empty fields or wrong values, so treat the output like any other untrusted input and check types and ranges before using it. Wrap the parse in a try block in production code. A reply cut off by a length limit can still be invalid JSON, so check finish_reason before you trust it.
Let the model call your functions
Tool calling lets the model ask your program to do something, such as look up an order, then continue with the result. You describe functions in tools, the model answers with tool_calls if it wants one, you run it, and you return the output as a message with the role tool.
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.uncensoredaimodel.com/v1",
api_key=os.environ["UNCENSORED_API_KEY"],
)
tools = [{
"type": "function",
"function": {
"name": "get_order_status",
"description": "Look up the status of an order by its id.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
},
}]
messages = [{"role": "user", "content": "Where is order A-1042?"}]
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 = {"order_id": args["order_id"], "status": "shipped"}
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)The status above is hard-coded for the demo, and the same pattern scales to several tools, since the model can request more than one call in a single reply and you answer each with its own tool message. In a real app, that line would query your database or another service. Streamed responses can carry tool calls too, delivered as tool_calls deltas that you stitch together.
Prompt habits and common mistakes
Good results depend less on tricks and more on being specific. State the task, the audience, the format and the length. Put input data in a clearly marked block, for example between lines of dashes, so the model does not confuse your data with your instructions. Show one or two examples when the output format matters. If the model keeps getting something wrong, say what you want instead of listing what to avoid.
Beginners also trip over the same handful of engineering mistakes:
- Putting the key in front-end code. Anything shipped to a browser can be read by every visitor. Call the API from a server.
- Assuming the model remembers. It does not. See the history example above.
- Ignoring finish_reason. A value of
lengthmeans the reply was cut off, which matters for JSON and for code. - No timeout or retry. Networks fail. Set a timeout and retry on 429 and on connection errors, with a short delay.
- Running everything in parallel. A loop of fifty simultaneous calls will hit the concurrency cap. Use a small worker pool.
- Never reading usage. Log token counts per request from day one. They tell you what a feature costs before the invoice does.
None of this needs a framework. A plain script with the official SDK, a message list and a few guards will take you surprisingly far, and it makes later migration to any other OpenAI-compatible service a matter of changing two settings.
Stream, handle limits, and watch cost
For anything a person reads, set stream to true so text appears as it is generated. Read each chunk and skip any that lack choices, because the last one carries usage figures.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.uncensoredaimodel.com/v1",
apiKey: process.env.UNCENSORED_API_KEY,
});
const stream = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Explain recursion in four sentences." }],
stream: true,
});
for await (const chunk of stream) {
const piece = chunk.choices[0]?.delta?.content;
if (piece) process.stdout.write(piece);
}Plan for limits from the start. A full key allows 8 concurrent requests and 300 per minute, and a trial key allows 2 and 60. Going over returns HTTP 429 with the code rate_limited or concurrency. A 429 with a Retry-After: 5 header means temporary overload, so wait five seconds and retry. A stream holds its concurrency slot until it ends.
For money, the arithmetic is simple. At $0.15 per million input tokens and $0.50 per million output tokens, a call with 800 tokens in and 200 out costs $0.00012 plus $0.0001, which is $0.00022. Failed or refused requests are not charged, and credit never expires. After the trial, top up with crypto (USDT on TRC20, USDC on Base), from $20 to $500. See the pricing page for bonuses on larger amounts, the docs for the full parameter list, and the overview of pay-per-token uncensored LLM access for how this service is priced and used.
