API Calls Using cURL: Chat Completions Step by Step
You can make API calls using curl with one command: a POST to /v1/chat/completions with a Bearer key and a JSON body. This page walks from the first request to streaming, tool calls and retry handling, all against a text-only uncensored LLM API.
Updated

Key points
One POST to /v1/chat/completions with a Bearer key and model uncensored is a full call.
Use -N for streaming, -i or -D to read the X-Balance-USD and rate limit headers.
Store the key in an environment variable and the body in a file for long prompts (limit 8 MB).
A 429 means slow down; with Retry-After: 5 wait five seconds and try again.
The smallest working request
An OpenAI-compatible API needs three things in a request: a URL, an Authorization header and a JSON body. Export your key first so it never ends up in your shell history or a pasted snippet:
export API_KEY="paste-your-key-here"
Then send the call:
curl https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [
{"role": "system", "content": "You are a concise writing assistant."},
{"role": "user", "content": "Describe a rainy harbor at night in two sentences."}
],
"max_tokens": 120
}'
The answer comes back as JSON. The text sits at choices[0].message.content, and a usage object reports prompt and completion tokens. If you do not have a key yet, the API key page explains sign-up and the one-click $0.50 trial, which needs no card and lasts 7 days.
The model is uncensored, an open-weight text model run by an independent provider and tuned to answer without content refusals for lawful adult use. It is not the official API of any model vendor, and it does not make images.
Read the response with jq
Raw JSON is hard to scan. Pipe the output to jq to pull out the part you want. The -s flag hides curl's progress meter, which keeps pipes clean.
curl -s https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"uncensored","messages":[{"role":"user","content":"Name three colors of dusk."}]}' \
| jq -r '.choices[0].message.content'
To see the token counts, use jq '.usage'. Multiply them by the prices ($0.15 per 1M input tokens, $0.50 per 1M output) and you have the exact cost of the call. A reply with 40 prompt tokens and 60 completion tokens costs 40 × 0.15 plus 60 × 0.50, which is 36 divided by 1,000,000: $0.000036.
You can also list the models the key can use:
curl -s https://api.sdxlnsfw.com/v1/models \
-H "Authorization: Bearer $API_KEY" | jq '.data[].id'
This is a quick connectivity test. If it prints uncensored, your key and URL are correct, and any later problem is in the body you send.
Send long prompts from a file
Inline JSON gets awkward as soon as the prompt has quotes, newlines or a few paragraphs. Put the body in a file and tell curl to read it. The @ prefix does that.
cat request.json
{
"model": "uncensored",
"temperature": 0.7,
"messages": [
{"role": "user", "content": "Summarize the following notes in five bullet points: ..."}
]
}
curl -s https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d @request.json
The maximum request body is 8 MB, which is far more than the 100,000-token context window needs in plain text. The window covers prompt plus completion, and max_tokens is optional: leave it out and the completion may use the rest of the window.
When the body is built by a script, jq -n is safer than string concatenation, because it escapes quotes for you:
jq -n --arg t "$(cat notes.txt)" \
'{model:"uncensored", messages:[{role:"user", content:("Summarize: " + $t)}]}' \
| curl -s https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d @-
The final -d @- tells curl to read the body from standard input.
Stream the reply
For a long answer you probably want text as it is produced. Add "stream": true to the body and -N to curl, which turns off output buffering.
curl -N https://api.sdxlnsfw.com/v1/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 lighthouse."}]
}'
The response is a server-sent event stream. Each line starts with data: and holds a JSON chunk with a small piece of text in choices[0].delta.content. The stream ends with data: [DONE], and usage is reported at the end. To see only the text, filter the lines:
curl -sN https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"uncensored","stream":true,"messages":[{"role":"user","content":"Count to five in words."}]}' \
| grep '^data: {' | sed 's/^data: //' | jq -rj '.choices[0].delta.content // empty'
One practical point: a streamed request holds its concurrency slot until the stream finishes. If you run several streaming curls in parallel, keep within the limit of your key.
JSON mode and tool calls
Two features make curl useful for scripts and pipelines. JSON mode forces valid JSON output:
curl -s https://api.sdxlnsfw.com/v1/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 with a JSON object with keys title and tags."},
{"role": "user", "content": "A story about a clockmaker who repairs memories."}
]
}' | jq -r '.choices[0].message.content | fromjson'
Mention the word JSON in your prompt, as above, so the model knows what shape you expect. The final fromjson parses the string inside the message into real JSON.
Tool calling uses the usual tools and tool_choice fields. You describe a function, the model answers with a tool_calls entry, your script runs the function and sends the result back as a message with role: "tool".
curl -s https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Roll a twenty-sided die for the guard check."}],
"tools": [{
"type": "function",
"function": {
"name": "roll_die",
"description": "Roll a die with the given number of sides",
"parameters": {"type": "object", "properties": {"sides": {"type": "integer"}}, "required": ["sides"]}
}
}],
"tool_choice": "auto"
}' | jq '.choices[0].message.tool_calls'
The quickstart docs cover the full tool loop with the SDKs.
Multi-turn chats from the shell
The API keeps no conversation state. To continue a chat, send the earlier messages again, with the model's own replies marked as assistant. A second turn looks like this:
curl -s https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [
{"role": "user", "content": "Give me a name for a tavern."},
{"role": "assistant", "content": "The Salted Anchor."},
{"role": "user", "content": "Now give it a rumor."}
]
}' | jq -r '.choices[0].message.content'
Because every turn resends the history, input tokens grow. Ten turns of 300 tokens each means the tenth call carries about 3,000 input tokens before your new message. That is still only 3,000 × 0.15 divided by 1,000,000, or $0.00045, but long chats are where cost comes from, so trim old turns once a conversation gets long.
Run many prompts in parallel with xargs
Curl alone makes one request at a time. To process a file of prompts, one per line, combine it with xargs and keep the parallelism under your concurrency limit. A full key allows 8 requests at once and a trial key allows 2, so -P 2 is the safe setting for a trial.
run() {
jq -n --arg p "$1" '{model:"uncensored", messages:[{role:"user", content:$p}]}' \
| curl -s https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" -d @- \
| jq -r '.choices[0].message.content'
}
export -f run
tr '\n' '\0' < prompts.txt | xargs -0 -P 2 -I{} bash -c 'run "$1"' _ {}
Outputs may arrive out of order, so for real batch work write each result to a file named by line number. If you start hitting 429 responses, lower -P. The same pattern with Python or Node gives you better error handling, but a shell loop is often enough for a one-off job of a few hundred prompts.
Headers, balance and rate limits
By default curl hides response headers. Add -i to print them above the body, or -D - to dump them to the terminal while keeping the body separate. Four headers are worth knowing:
X-Request-Id: quote it when you contact support about a specific call.X-Balance-USD: the credit left after the call.X-RateLimit-Limit-Requests: requests allowed per minute for your key.X-RateLimit-Limit-Concurrency: simultaneous requests allowed.
A full key allows 8 concurrent requests and 300 requests per minute; a trial key allows 2 and 60. Go over and the API answers HTTP 429. The error code rate_limited means too many requests per minute, concurrency means too many at once. A 429 with a Retry-After: 5 header signals temporary overload, so wait five seconds.
Curl has retries built in for transient failures, but a fixed delay matching that header works well:
curl -s --retry 3 --retry-delay 5 --retry-all-errors \
https://api.sdxlnsfw.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"uncensored","messages":[{"role":"user","content":"Say hello."}]}'
Failed or refused requests are not charged, so retries on errors do not drain your balance. Pricing details and top-up amounts are on the pricing page; the site takes crypto only, with USDT on TRC20 or USDC on Base.
Debugging a request that fails
When a call does not behave, make curl talk. Add -v to see the request headers it sent and the status line it got back. Add -w "\n%{http_code} %{time_total}s\n" to print the HTTP status and the total time after the body. A status in the 400 range means the request was wrong: a bad key, a malformed body or a missing field. A 429 means a limit, as described above.
Validate your JSON before you blame the server. Run the body through jq . first; if jq complains, curl would have sent broken JSON too. Check that the model field reads exactly uncensored, in lowercase.
If everything looks right and the reply is empty or cut short, look at finish_reason in the response. A value of length means the reply hit your max_tokens cap. Raise it, or remove it and let the completion use the rest of the window. Keep the X-Request-Id value from the failing call and send it to support if the cause is not clear.
Common mistakes
- Single quotes around a body that contains a single quote. An apostrophe in the prompt ends the shell string early. Use a file with
-d @request.json. - Missing Content-Type. Without
Content-Type: application/jsonthe body may not be parsed. - Wrong URL. The base is
https://api.sdxlnsfw.com/v1; the path is/chat/completions. Do not repeat/v1. - Key in the wrong place. It goes in the header as
Bearerplus the key, not in the URL. - Expecting images. This API is text only. For an SDXL workflow it writes the prompts and scripts, not the pictures. The chat API overview shows where text fits in such a pipeline.
The hard content rule applies to every request: nothing involving minors. Beyond that, the model is meant for lawful adult use, and prompts are not used for training.
More guides
Questions and answers
What is the base URL for curl calls?
Use https://api.sdxlnsfw.com/v1, then append /chat/completions for chat or /models to list models. Send your key as Authorization: Bearer YOUR_KEY.
How do I stream a response with curl?
Set stream to true in the JSON body and run curl with the -N flag. The reply arrives as server-sent events, one data: line per chunk, ending with data: [DONE].
Why do I get a 429 error?
You passed a limit. The code rate_limited means too many requests per minute, concurrency means too many at once, and a Retry-After: 5 header means temporary overload.
How can I check my balance from the command line?
Run curl with -i and read the X-Balance-USD response header, which shows the credit left after the call.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.