Uncensored Aichat/How to Curl an API: Chat Request Examples
How to Curl an API: Chat Request Examples
curl is the fastest way to test an HTTP API: one command, no code, no SDK. This page builds a working request piece by piece against a live chat completions endpoint and shows how to read the result.

A working command first
Here is how to curl api endpoints in the form you will use most often: a POST with a JSON body and a bearer token. The example sends one chat message to this site's API and prints the raw JSON response. Replace YOUR_KEY with your key, run it in a terminal, and you should see a reply within a few seconds.
curl https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [
{"role": "user", "content": "Write one sentence about a lighthouse."}
]
}'That is the whole pattern. The rest of this page explains each part so you can adapt it, and then adds streaming, JSON mode, tool calls and a list of errors you are likely to meet. If you do not have a key yet, the key page explains how to get one. The quickstart covers the same request in other tools.
What each part of the command does
| Piece | Purpose |
|---|---|
curl URL | Sends a request to the address. The default method is GET. |
-H "Authorization: Bearer YOUR_KEY" | Identifies you. The word Bearer and a space must come before the key. |
-H "Content-Type: application/json" | Tells the server the body is JSON. |
-d '...' | Supplies the body. Giving -d switches the method to POST automatically. |
\ at line end | Continues the command on the next line in bash or zsh. |
The body fields: model must be uncensored. messages is a list of objects with a role (system, user or assistant) and content. Optional fields such as temperature, top_p, stop, seed and max_tokens go in the same object. If you leave out max_tokens, the reply can use the rest of the 100,000-token window, which is why you may want to set it while experimenting.
Single quotes around the JSON keep the shell from touching the double quotes inside. If you need to put a shell variable into the body, switch to double quotes around the whole string and escape the inner ones, or better, read the body from a file as shown later.
Keep the key in a variable and read the reply
Typing a key into every command leaves it in your shell history. Store it once per session instead:
export API_KEY="paste-your-key-here"
curl -s https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "uncensored", "messages": [{"role": "user", "content": "Name three sea birds."}], "max_tokens": 80}' \
| jq -r '.choices[0].message.content'Here -s silences curl's progress meter so only the response is piped on, and jq -r prints the reply text without quotes. Install jq with your package manager if it is missing. Without jq, python3 -m json.tool will at least pretty-print the JSON.
One more habit: put a space before the command you want kept out of history. In bash and zsh, many setups skip history for lines that start with a space, though it depends on the HISTCONTROL setting. Another option is to read the key from a file with export API_KEY=$(cat ~/.api_key) and keep that file readable only by you. Either way, do not paste keys into shared terminals or screenshots, and replace the key if you do.
To use a longer prompt without wrestling with quotes, save the body to a file and let curl read it with @:
cat > body.json <<'JSON'
{
"model": "uncensored",
"messages": [
{"role": "system", "content": "You are a terse editor."},
{"role": "user", "content": "Tighten this sentence: The thing is that it was very, very cold outside."}
],
"max_tokens": 100
}
JSON
curl -s https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d @body.json | jq -r '.choices[0].message.content'List models and inspect the headers
A GET request needs no body. The first command lists the models the key can use, and it is the quickest check that your key and URL are right. The second sends a tiny chat request with -i so you can see the response headers along with the body.
curl https://api.uncensoredaichat.top/v1/models -H "Authorization: Bearer $API_KEY"
# same host, chat call with the model "uncensored", headers included
curl -i https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "uncensored", "messages": [{"role": "user", "content": "ping"}], "max_tokens": 5}'Among the headers, X-Request-Id identifies the call and is what you give support if something looks wrong. X-Balance-USD shows your remaining credit. X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency show your limits: 300 requests per minute and 8 concurrent for a full key, 60 and 2 for a trial key.
Streaming, JSON mode and tool calls from the command line
Streaming
Add "stream": true and the server sends events as they are produced. curl buffers output by default, so add -N to see the text arrive live.
curl -N https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "uncensored", "stream": true, "messages": [{"role": "user", "content": "Count from one to ten in words."}]}'You will see lines that begin with data:, each holding a small JSON chunk, and a final data: [DONE] line. The usage figures come at the end. A streaming request holds one of your concurrency slots until it finishes, so pressing Ctrl+C when you are done is good practice.
JSON mode
curl -s https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"response_format": {"type": "json_object"},
"messages": [{"role": "user", "content": "Return JSON with keys city and country for Lisbon."}]
}' | jq -r '.choices[0].message.content'Tool calls
Tools go in a tools array. If the model decides to use one, the response holds tool_calls instead of text, and you send the function result back with a message whose role is tool. In curl that is a second request that repeats the earlier messages, so most people test the first leg in curl and write the loop in code.
curl -s https://api.uncensoredaichat.top/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "What is the weather in Oslo?"}],
"tools": [{"type": "function", "function": {"name": "get_weather", "description": "Get current weather for a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}],
"tool_choice": "auto"
}' | jq '.choices[0].message'Errors and how to fix them
| You see | Cause | Fix |
|---|---|---|
401 or an authentication error | Missing key, no Bearer prefix, or a stray space | Check the header text and the variable with echo ${#API_KEY} |
| 404 or not found | Wrong path, such as a doubled /v1 | Use exactly https://api.uncensoredaichat.top/v1/chat/completions |
| Invalid JSON error | Quote or comma mistake in the body | Move the body to a file and check it with jq . body.json |
429, code rate_limited | Too many requests in a minute | Wait and retry |
429, code concurrency | Too many requests running together | Let running calls finish; streams count until they end |
429 with Retry-After: 5 | Temporary overload | Wait five seconds, then retry |
When a command fails and the message is unclear, read the status code first, then the body. The body of an error response is JSON with a message, and it usually names the field or the problem directly.
Add -v to see the full request curl sends when something is unclear. On Windows, the Command Prompt does not treat single quotes the same way; use PowerShell with a here-string or a body file, and use curl.exe by name so PowerShell does not substitute its own alias.
Cost of a curl session and next steps
Testing from the command line is cheap. Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. A request with 500 input tokens and 200 output tokens costs $0.000075 plus $0.0001, which is $0.000175, so a hundred of them cost $0.0175. Failed or refused requests are not charged. New users can claim $0.50 of trial credit with one click after sign-up; it needs no payment method and is valid for 7 days.
Beyond the trial, top-ups are any whole amount from $20 to $500, with +5% from $50, +10% from $100 and +15% from $200, paid by crypto (USDT on TRC20, USDC on Base). Credit never expires. See the pricing page for details, and the page on OpenAI-compatible access if you are coming from another gateway. Prompts are not used for training. The model is for lawful adult use, and sexual content involving minors is not allowed.
More guides
Questions and answers
Which headers does a curl API call need?
Authorization with the value Bearer plus your key, and Content-Type set to application/json for requests with a body.
How do I curl a POST request?
Use -d with the JSON body, or -d @file.json to read it from a file. curl switches to POST automatically when you give -d.
Why does curl show nothing while streaming?
curl buffers output. Add -N to disable buffering and the text appears as the server sends it.
What is the endpoint and model for this API?
The URL is https://api.uncensoredaichat.top/v1/chat/completions and the model is uncensored.
Does a test call cost money?
Yes, a small amount, billed per token. A short test costs a fraction of a cent, and failed requests are not charged.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.