EN ▾

OpenAI Compatible API curl Cheat Sheet

This is a working cheat sheet of OpenAI compatible API curl commands: chat, streaming, JSON output, tools, model list and balance. Every example uses one base URL, one key variable and the model id uncensored.

Updated

Terminal window sending streams of light to a cloud server, representing curl calls to an API
Two glowing bridges linking app blocks to a server tower, representing a switch between compatible APIs

Key points

  • Set two shell variables once, then every command is a short copy-paste.
  • Use -N with stream true to see tokens as they arrive, and -i to read headers such as X-Balance-USD.
  • Check your credit with GET /v1/balance or the OpenAI-style credit_grants path.
  • 429 means a limit: wait for Retry-After, then retry; failed requests are not charged.

Set up two variables

Every call below needs the same base URL and key, so put them in variables. Get a key from the API key page; new accounts can claim $0.50 of trial credit with one click.

export BASE="https://api.geminiuncensored.com/v1"
export KEY="your-key-here"

This page gives you an OpenAI compatible API curl reference you can paste into a terminal, so the examples stay minimal. Auth is always the same header, Authorization: Bearer $KEY, which the key header article covers in more depth. The model id is uncensored everywhere.

Basic chat completion

curl "$BASE/chat/completions" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "user", "content": "Give me three names for a fictional port city."}
    ]
  }'

Two details save time later. First, the quotes around the URL matter: "$BASE/chat/completions" must be double-quoted so the shell expands the variable, while the JSON body goes in single quotes so the double quotes inside it survive. Second, curl sends a POST automatically when you pass -d, so you do not need -X POST. If your prompt contains apostrophes, the single-quoted body will break; in that case write the JSON to a file and send it with -d @body.json.

The reply text is at choices[0].message.content in the JSON. Add | jq -r '.choices[0].message.content' to print only the text, if you have jq installed. The usage object lists prompt, completion and total tokens, which you need for cost tracking.

Keep a payload in a file

Long prompts and multi-turn tests are easier to manage as files. Save the request body once, edit it in your editor, and send it with @:

cat > body.json <<'JSON'
{
  "model": "uncensored",
  "temperature": 0.3,
  "messages": [
    {"role": "system", "content": "Answer in at most two sentences."},
    {"role": "user", "content": "Why is the sky blue?"}
  ]
}
JSON

curl -s "$BASE/chat/completions" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d @body.json | jq -r '.choices[0].message.content'

This also avoids shell quoting trouble on Windows terminals, where single quotes behave differently. Files are easy to commit to a repository too, so a teammate can rerun the same request and get a comparable answer. Keep the key out of the file and in the environment variable.

System prompt and sampling parameters

curl "$BASE/chat/completions" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "temperature": 0.7,
    "top_p": 0.95,
    "max_tokens": 300,
    "seed": 42,
    "stop": ["###"],
    "messages": [
      {"role": "system", "content": "You are a terse editor. Reply in one paragraph."},
      {"role": "user", "content": "Tighten: The meeting, which was long, went on for a very long time."}
    ]
  }'

The messages array is the whole conversation. A system message sets behaviour, user messages carry your input, and earlier assistant messages carry history. There is no session on the server, so for a multi-turn test you append each reply to the array yourself and send the longer array next time. That is the single most common surprise for people who expect a chat to remember things on its own.

Temperature, top_p, stop, seed and the frequency and presence penalties are passed through to the model. max_tokens is optional: leave it out and the completion can use the rest of the 100,000-token window. A fixed seed with low temperature makes test runs easier to compare.

Streaming

curl -N "$BASE/chat/completions" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "stream": true,
    "messages": [{"role": "user", "content": "Describe a thunderstorm in four sentences."}]
  }'

Without streaming, curl waits until the whole completion is generated and prints it at once. For short answers that is fine. For long ones, streaming shows output within moments and lets you cut the request off early with Ctrl+C if the answer is going the wrong way, which saves tokens.

The -N flag turns off curl's output buffering, so lines starting with data: appear as the server sends them. The stream ends with data: [DONE], and usage arrives in the last chunk. A streamed request holds one of your concurrency slots until the stream closes, which matters if you run many in parallel.

JSON mode and tool calls

For machine-readable output, set response_format. Mention JSON in the prompt as well, so the model knows what shape you want.

curl "$BASE/chat/completions" \
  -H "Authorization: Bearer $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 the capital of Peru."}
    ]
  }'

JSON mode asks the model for valid JSON but does not enforce your schema, so parse defensively and validate keys on your side. Keep the instruction explicit ("return JSON with keys city and country") and add a short example if the structure is nested. A low temperature, around 0.2, helps with stable output formats.

Tool calling uses the familiar structure: define tools, optionally set tool_choice, read tool_calls from the reply, run the function yourself, and send the result back as a message with role: "tool".

curl "$BASE/chat/completions" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "tool_choice": "auto",
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }],
    "messages": [{"role": "user", "content": "What is the weather in Lima?"}]
  }'

Models, balance and the Responses endpoint

List what the endpoint exposes. You should see the id uncensored:

# the response lists one model id: uncensored
curl "$BASE/models" -H "Authorization: Bearer $KEY"

Check your remaining credit with either route:

curl "$BASE/balance" -H "Authorization: Bearer $KEY"
curl "$BASE/dashboard/billing/credit_grants" -H "Authorization: Bearer $KEY"

The second path mimics the OpenAI-style billing endpoint, for tools that expect it. The same number appears in the X-Balance-USD header of every response. The newer Responses format is also served:

curl "$BASE/responses" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "uncensored", "input": "Say hello in three languages."}'

Read headers and handle errors

When something goes wrong, curl gives you more than a wrapper library does, because you see the raw response. Check the status line first, then the body: errors come back as JSON with a code you can match against the list below.

Add -i to print response headers, or -D - to dump them while still parsing the body. You will see X-Request-Id (quote it when you ask support about a call), X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency.

  • 401: missing or wrong key. Check the Bearer prefix and stray whitespace.
  • 429 with code rate_limited: too many requests per minute. A full key allows 300; a trial key, 60.
  • 429 with code concurrency: too many in flight. A full key allows 8; a trial key, 2.
  • 429 with Retry-After: 5: temporary overload. Wait the stated seconds and retry.
  • Large bodies: the maximum request body is 8 MB.

Here is a tiny retry wrapper for shell scripts:

for i in 1 2 3; do
  code=$(curl -s -o out.json -w "%{http_code}" "$BASE/chat/completions" \
    -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
    -d '{"model":"uncensored","messages":[{"role":"user","content":"ping"}]}')
  [ "$code" != "429" ] && break
  sleep 5
done
cat out.json

Failed or refused requests are not charged, so retries do not cost you anything extra when they fail.

What a curl test costs

It helps to know what the numbers look like before you script anything. One English word is roughly 1.3 tokens, so a 500-word reply is about 650 output tokens. A prompt of 2,000 words is about 2,600 input tokens. The usage block in each response gives the exact figures, and since you pay per token, logging them for every call is the easiest form of cost control. Combine it with the balance check above and you can stop a batch job when credit runs low.

Scale this up with simple arithmetic. A script that sends 200 prompts of 800 input and 400 output tokens each uses 160,000 input tokens and 80,000 output tokens. That is 0.16 × $0.15 = $0.024 for input and 0.08 × $0.50 = $0.04 for output, or $0.064 for the whole batch. Numbers this small mean the main limit on a batch job is the rate limit, not the price.

A typical test with 1,000 input tokens and 500 output tokens costs 1,000 × $0.15 / 1M + 500 × $0.50 / 1M = $0.00015 + $0.00025 = $0.0004. The $0.50 trial credit covers about 1,250 such calls. When you need more, top up from $20 to $500 with USDT on TRC20 or USDC on Base; the pricing page lists the bonuses. For the full parameter list, use the docs, and for a wider view of the product see the OpenAI-compatible Gemini alternative page.

Questions and answers

What header does the API need?

Authorization: Bearer followed by your key, plus Content-Type: application/json on POST requests.

Why does curl show nothing until the end when streaming?

Output buffering. Add the -N flag so curl prints each chunk as it arrives.

How do I see my balance from the command line?

Call GET /v1/balance or the OpenAI-style /v1/dashboard/billing/credit_grants path. The X-Balance-USD response header also shows it.

Do I need to set max_tokens?

No, it is optional. Without it, the completion can use whatever is left of the 100,000-token window.

Your key is one form away

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