What is an AI API? First Request, Tokens, and Errors
So what is an AI API? It is an interface that lets you use a language model via HTTP requests from your own code instead of a chat window. In this article, you will see the first request, token logic, and common errors step by step.


Highlights
- The API is an HTTP gateway between your app and the model: you send messages, you get responses.
- Cost is measured by tokens; input and output are priced separately.
- Because it is an OpenAI-compatible API, existing libraries work as long as you change the base URL and the API key.
- A 429 error usually occurs when you exceed the per-minute request or concurrent requests limit.
What does an AI API do?
On chat sites, you type into a box and read the response on screen. With the API, a program does the same thing: your code sends a request to the model, and the model returns the response as JSON. This allows the response to go directly to a web page, bot, script, or your own app.
Typical uses include classifying customer messages, summarizing long text, extracting structured data from a form, speaking characters in a game or story app, and generating code. The chat interface is for a single human; the API repeats the same task automatically hundreds of times.
This API offers a single open-weight model tuned to respond without content rejection for legal adult use. It is text-only: it does not generate images, audio, or video, and does not offer embeddings or fine-tuning. Sexually explicit content involving minors is prohibited in all cases. We explain the filtering topic separately on the uncensored AI page.
The answer to the question "ready-made chat site or API" lies in the volume of repetitions. If you ask a question once, the chat interface is enough. If you process hundreds of records daily, feed output into another system, or display the model in your own product, you need the API. With the API, you define the interface, roles, system prompt, and response format; in return, error handling, balance tracking, and security are up to you.
You do not need to set up a product to get started. Processing ten records with a small script and checking usage info is the fastest way to understand both the model and the cost. The free trial credit is sufficient for this.
How does a request work?
Each request has three things: the address, the key, and the messages. The address (base URL) is https://api.sansursuzapi.com/v1. The key goes with the Authorization: Bearer ANAHTAR header. The messages are in a list, and each message has a role.
system: instructions telling the model how to behave.user: your question or command.assistant: the model's previous answers.
The model does not remember the previous conversation with each request. If you want the chat to continue, you send the history again every time. This has significant implications for token accounting; you will see below.
The main endpoint is POST /v1/chat/completions. There is also POST /v1/responses and for the model list GET /v1/models. The model ID is written as uncensored.
Send the first request
First, get an API key from the API key page. New users can get a $0.50 free trial credit with one click after signing up; no payment info is required, and it is valid for 7 days. The following command is sufficient in the terminal:
curl https://api.sansursuzapi.com/v1/chat/completions \
-H "Authorization: Bearer ANAHTARIN" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [
{"role": "system", "content": "Kısa ve net cevap ver."},
{"role": "user", "content": "API nedir, tek cümleyle açıkla."}
]
}'
The official OpenAI library works in Python; you just change the base URL and API key:
from openai import OpenAI
client = OpenAI(
base_url="https://api.sansursuzapi.com/v1",
api_key="ANAHTARIN",
)
yanit = client.chat.completions.create(
model="uncensored",
messages=[
{"role": "system", "content": "Kısa ve net cevap ver."},
{"role": "user", "content": "API nedir, tek cümleyle açıkla."},
],
)
print(yanit.choices[0].message.content)
print(yanit.usage) # prompt_tokens, completion_tokens
The response contains text in the choices[0].message.content field and the token count used in the usage field. All steps are also in the documentation.
What is a token, and how is it billed?
The model processes text in chunks called tokens, not words. A token is sometimes a word, sometimes part of a word. Because Turkish is an agglutinative language, a Turkish sentence usually takes more tokens than an English sentence with the same meaning. Instead of guessing the exact count, it is best to check the usage field in the response.
The price has two components: input tokens are $0.15 per 1,000,000 tokens, output tokens are $0.50 per 1,000,000 tokens. No subscription; prepaid balance is consumed. Example:
- Request: 1,000 input + 500 output tokens.
- Input: 1,000 × $0.15 / 1,000,000 = $0.00015.
- Output: 500 × $0.50 / 1,000,000 = $0.00025.
- Total: $0.0004. So 1,000 such requests cost $0.40.
Because you resend the chat history with every request, the input grows with each turn. In a long conversation, most of the cost comes from this accumulated input. See the pricing page for detailed examples. The context window is 100,000 tokens (input and output combined); you don't have to provide max_tokens.
Common mistakes when thinking
The first mistake is sending no history and expecting the model to remember the previous conversation. The second is repeating a very long system prompt with every request, inflating input costs. The third is asking for very long answers without limiting the output; output tokens are about three times more expensive than input tokens ($0.50 vs $0.15). Specifying the output length explicitly in the prompt and, if necessary, setting max_tokens is a cheap precaution.
How to maintain conversation history?
The API is stateless: the server does not store previous requests. If you are writing a chat application, you maintain the list, adding the new message each turn and sending everything. The simplest form is:
from openai import OpenAI
client = OpenAI(base_url="https://api.sansursuzapi.com/v1", api_key="ANAHTARIN")
gecmis = [{"role": "system", "content": "Sen yardımsever bir asistansın."}]
while True:
soru = input("Sen: ")
gecmis.append({"role": "user", "content": soru})
r = client.chat.completions.create(model="uncensored", messages=gecmis)
cevap = r.choices[0].message.content
gecmis.append({"role": "assistant", "content": cevap})
print("Model:", cevap)
This loop works but the list keeps growing. Since the input token count increases each turn, both cost and latency rise. In practice, you shorten old messages or summarize them after a certain turn. Instead of waiting for the 100,000-token context window to fill, it is cheaper to truncate the conversation yourself.
Common features
| Feature | How to enable | What it does |
|---|---|---|
| Streaming | "stream": true | The answer comes in parts, so the user does not wait. |
| JSON mode | "response_format": {"type": "json_object"} | The answer is valid JSON, so it goes directly into the code. |
| Function calling | tools, tool_choice | The model wants to call your function; you return the result with role: "tool". |
| Randomness | temperature, top_p, seed | Controls how variable the answer is. |
You don't need any of them to start. Run a plain request first, then add one as needed. If streaming is enabled, usage information is provided at the end of the stream.
Displaying the answer via streaming
Streaming is used so the user doesn't stare at a blank screen while the whole text finishes. Example with Node:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.sansursuzapi.com/v1",
apiKey: process.env.API_KEY,
});
const stream = await client.chat.completions.create({
model: "uncensored",
stream: true,
messages: [{ role: "user", content: "Üç maddede API güvenliği anlat." }],
});
for await (const parca of stream) {
process.stdout.write(parca.choices[0]?.delta?.content ?? "");
}
The streaming request holds your concurrent request slot until it ends. If you will open streaming for many users at once, consider the 8 concurrent requests limit and pass requests through a queue.
Common errors and balance
In case of an error, the API returns an HTTP status code and description. The most common ones are:
- Authorization error: the key is misspelled or the
Bearerprefix is missing. Check the header and whether the key has spaces at the beginning or end. - 429,
rate_limited: per-minute request limit exceeded. The full key has 300 requests per minute, the trial key 60. - 429,
concurrency: too many concurrent requests. The full key allows 8 concurrent requests, while the trial key allows 2. - 429 and
Retry-After: 5: temporary overload. Wait 5 seconds and try again. - Body too large: the request body can be at most 8 MB.
Failed or rejected requests are not charged. Provide the X-Request-Id value from the response headers when contacting Support; X-Balance-USD shows your remaining balance. If you have an issue, the Support page will help.
Balance is topped up in integer amounts between $20 and $500. A 5% bonus is given starting from $50, 10% from $100, and 15% from $200. Payment is crypto only: USDT on TRC20 or USDC on Base. The balance remains indefinitely. Do not put your key in the browser frontend code or in a public repository; keep it as an environment variable on the server. The prompts you send are not used for model training.
Other guides
Frequently Asked Questions
Is the AI API free?
No, it works on a pay-as-you-go model. New users receive a $0.50 trial credit with a single click after signing up; no payment information is required, and it is valid for 7 days.
Do I need to be a programmer to use the API?
Knowing how to write a basic script is enough. You can also use ready-made tools like SillyTavern that accept OpenAI-compatible endpoints by entering the address and key without writing code.
What is the difference between ChatGPT and the API?
ChatGPT is a chat application. The API gives you programmatic access to the model itself; you can connect the output to your own app, database, or automation.
Which model ID should I write?
Write uncensored in the model field. You can also list available models with GET /v1/models.
Your key is just one form away
Create an account, copy the key, and change the base URL. That's all there is to the setup.