EN ▾
Try with trial credit
https://api.chataiunrestricted.com/v1

Uncensored LLM API for adults

Chat AI UnrestrictedWhat Is Chat API? Messages, Roles and Tokens

What Is Chat API? Messages, Roles and Tokens

What is chat api, in plain terms? It is an HTTP endpoint where you send a list of messages and get the model's next message back. Everything else, from roles to tokens to cost, follows from that one idea.

Last updated

Message cards on a conveyor entering a glowing cube, with small tokens spilling into a tray

Summary

  • A chat API takes a messages array, each with a role and content, and returns one assistant message.
  • It is stateless: you resend the history on every call, and tokens in plus tokens out decide the cost.
  • The context window is the total tokens the model can read and write in one call; here it is 100,000.
  • A minimal request needs three things: a URL, a key and a model name.

The idea in one paragraph

A chat API lets a program have a conversation with a language model. You send a request that contains the conversation so far, as a list of messages. The server runs the model and sends back the next message. If you want the exchange to continue, you add the reply and your next message to the list and send it again. The model keeps no notes between calls; the list is the only memory it has.

The most common design follows OpenAI's chat completions format, and many providers copy it so existing tools keep working. This site's API does the same: it is OpenAI-compatible, so any OpenAI SDK works after you change the base URL and key.

Anatomy of a request

A request is a JSON body with a model name and a messages array. Each message has a role and content. Three roles do most of the work.

RoleWho writes itWhat it is for
systemYou, the developerStanding instructions: persona, tone, format, rules
userThe end userWhat the person typed
assistantThe model, earlierPrevious replies, sent back so the model sees them

A fourth role, tool, carries the result of a function the model asked you to run. That is how tool calling works: the model returns a request to call a function, your code runs it, and you send the output back as a role: "tool" message.

Other fields are optional settings. temperature controls randomness: lower is more predictable, higher is more varied. max_tokens caps the reply length. stream turns on token-by-token delivery. response_format with json_object asks for valid JSON.

A minimal working example

Here is the smallest useful request. It needs the URL, a key, a model name and one message.

curl https://api.chataiunrestricted.com/v1/chat/completions \
  -H "Authorization: Bearer $CHAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You explain things in plain words."},
      {"role": "user", "content": "What is a token?"}
    ]
  }'

The same thing in Python:

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.chataiunrestricted.com/v1",
    api_key=os.environ["CHAT_API_KEY"],
)

resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You explain things in plain words."},
        {"role": "user", "content": "What is a token?"},
    ],
)
print(resp.choices[0].message.content)

You need a key first. Sign up on the key page, where new users can claim $0.50 of trial credit with one click.

Reading the response

The reply is a JSON object. These are illustrative values, shown to explain the structure:

{
  "id": "example-id",
  "object": "chat.completion",
  "model": "uncensored",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "A token is a small chunk of text..."},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 28, "completion_tokens": 45, "total_tokens": 73}
}

The answer is in choices[0].message.content. finish_reason says why generation ended: stop for a natural end, length if it hit a token limit. The usage block tells you how many tokens the request consumed, and that is what you are billed on. Response headers add X-Request-Id for tracing and X-Balance-USD for your remaining credit.

Why you resend the history

The server is stateless. To continue the conversation, build the next request from the earlier messages plus the new one:

history = [{"role": "system", "content": "You explain things in plain words."}]

def say(text):
    history.append({"role": "user", "content": text})
    resp = client.chat.completions.create(model="uncensored", messages=history)
    reply = resp.choices[0].message.content
    history.append({"role": "assistant", "content": reply})
    return reply

print(say("What is a token?"))
print(say("Give me an example in French."))

The second call works because the first question and answer are in history. Drop them, and "an example" has nothing to refer to. This is also why long chats get more expensive: each turn resends everything before it.

Tokens, context window and cost

Models read and write tokens, not words. A token is a chunk of text; in English a rule of thumb is about four characters, or three quarters of a word. The exact split depends on the model, so use the usage block for real counts.

The context window is the most the model can handle in one call, counting the prompt and the reply together. Here it is 100,000 tokens, roughly 75,000 English words by the rule of thumb. Completion can use whatever the prompt leaves free, and max_tokens is optional.

Billing uses the same counts. Input costs $0.15 per 1M tokens and output costs $0.50 per 1M. The illustrative response above used 28 input and 45 output tokens: 28 / 1,000,000 x $0.15 = $0.0000042 and 45 / 1,000,000 x $0.50 = $0.0000225, which adds to about $0.0000267. A fuller chat turn with 3,000 input and 400 output tokens costs $0.00065. Pricing is pay as you go from prepaid credit, with details on the pricing page.

Mistakes beginners make

  • Leaving out /v1 in the base URL. The result is a 404 that looks like the API is down. Use the full base URL from your provider.
  • Expecting memory. If the model forgets your name between calls, the history was not sent. Send it every time.
  • Putting the key in front-end code. Anyone can read it. Call the API from a server and expose your own endpoint to the browser.
  • Ignoring finish_reason. A value of length means the reply was cut off by a token limit. Raise the limit or ask for a shorter answer.
  • Putting instructions in the wrong role. Standing rules belong in the system message. A user message is easier for the model to treat as one request among many.
  • Retrying without limit. On a 429 response, wait and retry a few times, then give up and report the error. Endless loops burn through rate limits.

Fix these six and most first projects work. For the full list of errors this API returns, see the docs.

Chat completions, responses and the models list

A chat API usually exposes more than one route. On this API there are three that matter:

  • POST /v1/chat/completions is the classic route used in every example above.
  • POST /v1/responses is the newer OpenAI-style route, for clients that already use it.
  • GET /v1/models returns the list of model IDs, which is a quick way to check that your key and base URL work. Here the model ID is uncensored.

If you are writing new code and have no preference, start with chat completions. It is the format most libraries and tutorials assume, and everything you learn there carries over to other providers that copy it.

Where to go from here

With the basics clear, the next topics are streaming, tool calling and error handling. The API docs cover them, including the limits: a full key allows 8 concurrent requests and 300 requests per minute, and a trial key allows 2 and 60. For a longer walkthrough of wiring this into an app, read the integration guide.

One note on scope. This API is text only, with one open-weight model tuned to answer without content refusals for lawful adult use. It does not generate images, audio or video and has no embeddings or fine-tuning. Sexual content involving minors is not allowed.

Common questions

Is a chat API the same as a chatbot?

No. A chatbot is a finished product with an interface. A chat API is the building block that a developer calls from code to get model replies.

Does the API remember earlier messages?

No. It is stateless, so you send the earlier messages again with every request.

What is a token?

A chunk of text the model reads or writes, roughly four characters of English. Cost and the context window are counted in tokens.

Do I need the OpenAI library?

It is the easiest option, but any HTTP client works. Send a POST to /v1/chat/completions with a Bearer key and a JSON body.

Your API key is next

Sign up, grab the key, swap the endpoint URL. That is all there is to it.

https://api.chataiunrestricted.com/v1Try with trial credit