EN ▾
Get API key

Uncensored AIHow to Use an AI Image API

How to Access an API Using curl: Chat Completions

To access an API using curl you send an HTTPS request with a bearer token and a JSON body. This guide does it against an OpenAI-compatible chat API: list models, send a prompt, stream the answer, and read the errors.

Updated

Terminal sending data cubes through a pipe to a server tower, illustrating curl requests to an API

01Uncensored AI

Key points

  1. Text APIs handle prompt construction, script writing, and metadata extraction independently of image generation models.

  2. OpenAI-compatible endpoints allow direct integration using standard SDKs without custom protocol development.

  3. Streaming support enables real-time token delivery, essential for interactive prompt refinement workflows.

  4. Token pricing is usage-based, with specific limits on context windows and request rates.

What you need first

Three things: a terminal with curl (it ships with macOS, most Linux distributions and current Windows 10 and 11), an API key, and the base URL. The base URL here is https://api.uncensoredaiimage.com/v1. The API is text only. It is a chat model that returns text, not an image generator, even though the domain name might suggest otherwise.

Get the key on the API key page. Sign up with Google or with an email and password, then claim the $0.50 trial credit with one click. It is valid for 7 days, one per person, and you need no payment to start. Copy the key and store it in an environment variable, so it never ends up in your shell history or in a script you share:

export API_KEY="paste-your-key-here"
export API_URL="https://api.uncensoredaiimage.com/v1"

On Windows PowerShell, use $env:API_KEY = "..." instead, and use curl.exe rather than curl, because plain curl is an alias for another command there. The examples below use bash-style quoting.

Step 1: check the key with GET /v1/models

The simplest request has no body. It asks the server which models it serves, and it proves that your key and URL are correct.

curl "$API_URL/models" \
  -H "Authorization: Bearer $API_KEY"

You get a JSON object listing the model, with the ID uncensored. This is the ID you put in every chat request. If you get an error instead, check three things in order: the key has no stray spaces or quotes, the URL ends in /v1 and not /v1/ followed by another /v1, and the header is spelled Authorization with the word Bearer and a space before the key.

Pipe the output to jq if you have it installed. It makes JSON readable:

curl -s "$API_URL/models" -H "Authorization: Bearer $API_KEY" | jq .

Step 2: send a chat request

Now the real call. A chat request is a POST to /chat/completions with a JSON body containing the model and a list of messages. Two headers are required: the bearer token and the content type.

curl "$API_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Give me three names for a fantasy tavern."}
    ],
    "temperature": 0.8,
    "max_tokens": 200
  }'

The reply holds a choices array. The text sits in choices[0].message.content, and a usage object reports prompt and completion tokens. To print only the text, add jq:

curl -s "$API_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Say hello in five languages."}]}' \
  | jq -r '.choices[0].message.content'

The max_tokens field is optional. Without it, the completion may use the rest of the 100,000-token window, so set a cap while you experiment. Quoting is the usual stumbling block. The JSON uses double quotes, so wrap the whole body in single quotes. If your prompt itself contains a single quote, move the body to a file and use -d @request.json.

Step 3: read the response headers

Add -i to include headers in the output, or -D - to dump them while still piping the body elsewhere.

curl -i "$API_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"ping"}],"max_tokens":5}'

Four headers are worth knowing:

  • X-Request-Id identifies the call. Keep it when you report a problem.
  • X-Balance-USD shows your remaining credit.
  • X-RateLimit-Limit-Requests is the requests-per-minute limit on your key.
  • X-RateLimit-Limit-Concurrency is the number of requests you may have in flight at once.

A full key allows 300 requests per minute and 8 concurrent requests. A trial key allows 60 and 2. Checking these headers on a first call is a quick way to see which kind of key you are using.

Step 4: stream the answer

Set "stream": true and the server sends the reply as server-sent events, a series of lines starting with data:. By default curl buffers output, so you see nothing until the end. The -N flag turns the buffer off.

curl -N "$API_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "stream": true,
    "messages": [{"role": "user", "content": "Write a four-line poem about a night train."}]
  }'

Each event carries a small piece of text in choices[0].delta.content. The stream ends with data: [DONE], and token usage arrives at the end. To pull out just the text with a shell filter:

curl -sN "$API_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","stream":true,"messages":[{"role":"user","content":"Count to ten."}]}' \
  | grep --line-buffered '^data: {' | sed -u 's/^data: //' \
  | jq --unbuffered -rj '.choices[0].delta.content // empty'

Remember that a streamed request occupies one of your concurrent slots until the stream ends. If you start a stream in the background and forget it, that slot stays taken.

JSON mode and tool calls from the shell

For scripts, you often want the model to return machine-readable output. Add response_format and describe the keys in the prompt:

curl -s "$API_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "response_format": {"type": "json_object"},
    "messages": [
      {"role": "system", "content": "Reply as JSON with keys title and tags (array of strings)."},
      {"role": "user", "content": "A short note about a lighthouse keeper who collects radios."}
    ]
  }' | jq -r '.choices[0].message.content | fromjson'

Tool calling works through the tools and tool_choice fields, and the results go back as messages with role: "tool". It needs a loop that runs your function between requests, so it fits a Python or Node script better than a one-line curl. The API quickstart covers the format, and the API overview page explains how the service is organised.

Other fields such as temperature, top_p, stop, seed and the penalties go straight in the JSON body and are passed to the model. The request body can be up to 8 MB.

Turn it into a reusable shell function

Typing the same headers each time gets old. Wrap the call in a small function and keep a conversation in a file, so you can test multi-turn behaviour without writing a program. This version takes the prompt as its first argument and builds the JSON with jq, which handles quotes and newlines for you.

ask() {
  jq -n --arg p "$1" '{model:"uncensored", max_tokens:400,
      messages:[{role:"user", content:$p}]}'   | curl -s --fail-with-body "$API_URL/chat/completions"       -H "Authorization: Bearer $API_KEY"       -H "Content-Type: application/json"       -d @-   | jq -r '.choices[0].message.content'
}

ask "Summarise the plot of a heist story in two sentences."

The -d @- flag reads the body from standard input, which avoids every quoting problem in one move. Because the function builds the JSON with --arg, a prompt full of apostrophes and double quotes still arrives intact. Put the function in your shell profile and you have a one-word command for quick checks, prompt tuning and cron jobs.

For multi-turn tests, keep a messages array in a JSON file. Append the assistant's reply and your next user line, then send the whole file again. The API does not remember earlier requests, so every call must carry the history you want the model to see. That also means the input cost grows with each turn, which is worth knowing before you script a long loop.

Errors, retries, mistakes and cost

Add --fail-with-body (curl 7.76 or newer) so the exit code is non-zero on HTTP errors while the error JSON is still printed. In scripts, that lets you test $? instead of parsing text.

The limit error is HTTP 429. Its JSON has a code: rate_limited means you exceeded the requests per minute, and concurrency means you have too many requests running at once. On temporary overload the server also returns 429 with Retry-After: 5. curl can retry for you:

curl --retry 3 --retry-delay 5 --fail-with-body "$API_URL/models" \
  -H "Authorization: Bearer $API_KEY"

curl honours the Retry-After header on retried responses, so the delay follows what the server asks for. Failed and refused requests are not charged.

The price is $0.15 per 1M input tokens and $0.50 per 1M output tokens, from prepaid credit with no subscription. A test call with a 1,000-token prompt and a 500-token answer costs 1,000 x $0.15 / 1M = $0.00015 for input plus 500 x $0.50 / 1M = $0.00025 for output, a total of $0.0004. You could run 1,250 of those on the $0.50 trial. Paid top-ups run from $20 to $500, with a bonus of 5% from $50, 10% from $100 and 15% from $200, paid in USDT on TRC20 or USDC on Base. See the pricing page.

Common mistakes

Most failed first calls come from a short list. A missing Content-Type header makes the server unable to read the body as JSON. Smart quotes pasted from a web page or a chat window break the JSON. A key copied with a trailing newline fails authentication, so use printf %s or check with echo "$API_KEY" | wc -c. Using the wrong path, for example /v1/completions instead of /v1/chat/completions, returns an error, because only chat completions and the model list exist. And a trailing comma in the JSON body is invalid, however natural it feels in other languages.

When something still fails, rerun with -v to see the request that curl actually sent, then compare it with the examples above line by line. Keep the X-Request-Id value from the failing response. Never paste your key into a public forum while asking for help, and if you do, treat it as exposed and replace it.

02Uncensored AI

Questions and answers

What headers does the API need?

Authorization: Bearer with your key on every call, and Content-Type: application/json on POST requests.

Which URL do I call for chat?

POST https://api.uncensoredaiimage.com/v1/chat/completions, with the model set to uncensored. GET /v1/models lists the model.

Why do I see nothing while streaming?

curl buffers output by default. Add -N to turn buffering off, and set stream to true in the body.

What does HTTP 429 mean here?

You hit a limit. The error code is rate_limited for requests per minute or concurrency for too many simultaneous requests, and Retry-After: 5 appears on temporary overload.

Uncensored AIuncensoredaiimage.com

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key