EN ▾
Get API key

curl POST API Example for a Chat Completions Endpoint

Here is a curl POST API example you can paste into a terminal and run in a minute, followed by streaming, JSON mode, tool calling and error handling. Only your key changes.

Updated

Terminal sending a request through a gateway and receiving cards of data back

The shortest request that works

If you only want a curl POST API example to copy, this is it. Replace the key, run it, and you get a JSON reply from the model.

export API_KEY="sk-your-key-here"

curl https://api.nsfwvideoapi.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 assistant."},
      {"role": "user", "content": "Give me three names for a fictional port city."}
    ]
  }'

The endpoint follows the OpenAI chat format, so anything you know about that format carries over. The model ID is uncensored, and the base URL is the only thing that differs from a stock OpenAI example. If you have no key yet, the API key page explains sign-up and the one-click trial credit.

What each part of the command does

Curl turns into a POST request as soon as you pass -d, so you do not need -X POST. You can add it for readability, but it is redundant, and in a few redirect cases it causes odd behaviour, so most people leave it out.

Single quotes around the JSON stop the shell from touching the double quotes inside. That works in bash and zsh. On Windows cmd the rules differ: use double quotes outside and escape the inner ones with a backslash, or put the body in a file and use -d @body.json, which behaves the same everywhere.

Before you send anything long, check that the key works with the cheap read-only call:

curl https://api.nsfwvideoapi.com/v1/models \
  -H "Authorization: Bearer $API_KEY"

A JSON list containing uncensored means the key and the URL are right. Any problem after that is in your request body.

Keep the key and the body out of your history

Typing a key straight into a command stores it in your shell history, and it shows up in process listings while curl runs. Two small habits fix this.

First, keep the key in an environment variable, as above. In a script, read it from a file that only you can open. Second, move the body into a file:

cat > body.json <<'BODY'
{
  "model": "uncensored",
  "temperature": 0.7,
  "max_tokens": 300,
  "messages": [
    {"role": "user", "content": "Write a four-line poem about a night train."}
  ]
}
BODY

curl https://api.nsfwvideoapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @body.json

The quoted 'BODY' stops the shell from expanding anything inside the heredoc. Now you can edit the prompt in an editor, keep several bodies side by side, and diff them when two runs behave differently. Parameters such as temperature, top_p, stop, seed and the penalties are passed through to the model, so a fixed seed with the same body is a handy way to compare two prompt edits.

Pull out just the reply with jq

The raw response is one long line of JSON. Piping it through jq gives you the text and the token counts, which is usually all you want in a terminal.

curl -s https://api.nsfwvideoapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @body.json | jq -r '.choices[0].message.content'

# token usage for the same call
curl -s https://api.nsfwvideoapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @body.json | jq '.usage'

The -s flag hides curl's progress meter, which otherwise gets mixed into piped output. The usage object shows prompt and completion tokens, and those two numbers are what billing is based on. If you want to turn them into dollars, the pricing page lists the rates and the top-up options.

If jq prints null, the response was probably an error object and not a completion. Run the call again without the pipe and read what came back.

Stream the answer with -N

Add "stream": true to the body and the server sends server-sent events: lines that start with data:, each holding a small JSON chunk, ending with data: [DONE]. Curl buffers output by default, so add -N (no buffering) or you will see nothing until the end.

curl -N https://api.nsfwvideoapi.com/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."}]
  }'

Each chunk carries a small piece of text under choices[0].delta.content. Usage is reported at the end of the stream, so you can still count tokens. To print only the text as it arrives, filter the stream:

curl -sN https://api.nsfwvideoapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @stream.json \
  | sed -u 's/^data: //' \
  | grep --line-buffered -v '^\[DONE\]' \
  | jq -rj '.choices[0].delta.content // empty'

The -u flag on GNU sed keeps it unbuffered; on macOS use gsed or a short Python script instead. One thing to remember: a streamed request holds its concurrency slot until the stream finishes. If you start a stream and then walk away from it without closing the connection, that slot stays busy.

JSON mode and tool calling from the command line

For structured output, set response_format to json_object. Tell the model in the prompt that you want JSON, and name the keys you expect.

curl -s https://api.nsfwvideoapi.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 JSON only, using the keys title and tags."},
      {"role": "user", "content": "Describe a lighthouse mystery novel."}
    ]
  }' | jq -r '.choices[0].message.content | fromjson'

The message content is a string holding JSON, which is why the last jq step runs fromjson on it.

Tool calling works through tools and tool_choice. You describe a function, the model replies with a tool_calls entry holding the function name and a JSON string of arguments, you run the function yourself, and you send the result back as a message with role set to tool.

curl -s https://api.nsfwvideoapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "tool_choice": "auto",
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_time",
        "description": "Get the current time in a city",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }],
    "messages": [{"role": "user", "content": "What time is it in Lisbon?"}]
  }' | jq '.choices[0].message.tool_calls'

The second request repeats the conversation and adds two messages: the assistant message containing the tool_calls, and a tool message with the matching tool_call_id and your result as content. The documentation has the full field list if you need it.

Read the headers and the errors

Add -i to see the status line and response headers along with the body. Four headers are worth knowing: X-Request-Id (quote it if you contact support), X-Balance-USD (your remaining credit), X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency.

curl -si https://api.nsfwvideoapi.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d @body.json | head -n 20

The limits on a full key are 8 concurrent requests and 300 requests per minute. A trial key gets 2 concurrent and 60 per minute. Go over and you receive HTTP 429, and the error code tells you which limit you hit:

Error codeMeaningWhat to do
rate_limitedToo many requests in one minuteSlow the loop down or add a short sleep
concurrencyToo many requests running at onceWait for open requests and streams to finish
429 with Retry-After: 5Temporary overloadWait five seconds and send the same request again

Curl can do the waiting for you. --retry 3 retries on transient failures, including HTTP 429, and it honours a Retry-After header when the server sends one. For a loop that fires many requests, add a pause between them rather than relying on retries, because a retry still counts against the per-minute limit. Failed requests are not charged, so a retry after an error costs you nothing extra.

Once a single call works, a loop turns curl into a small batch tool. This one reads one prompt per line from a file, sends each as its own request, and sleeps between calls so you stay well under the per-minute limit. At 300 requests per minute on a full key you could go faster, but a pause of a fraction of a second keeps the loop polite and easy to stop. The same pattern works for a quick regression check: keep a file of ten prompts you care about, run it after you change a system prompt, and compare the replies side by side. It is crude, yet it catches most prompt regressions before they reach users.

while IFS= read -r line; do
  jq -n --arg p "$line" '{model: "uncensored", messages: [{role: "user", content: $p}]}' \
  | curl -s https://api.nsfwvideoapi.com/v1/chat/completions \
      -H "Authorization: Bearer $API_KEY" \
      -H "Content-Type: application/json" \
      -d @- | jq -r '.choices[0].message.content'
  sleep 0.5
done < prompts.txt

Building the body with jq -n --arg matters, because it escapes quotes and newlines in the prompt for you. Pasting raw text into a JSON string by hand is how most invalid-JSON errors start. The -d @- option tells curl to read the body from standard input.

The request body can be up to 8 MB. If curl reports an error about the argument list being too long, the body is too big for the command line, and -d @file is the fix.

Common mistakes and how to fix them

When you are done testing with curl, moving the same body to the OpenAI SDK for Python or Node is a matter of changing two settings, the base URL and the key. The integration page shows how clients and tools that expect an OpenAI-style endpoint are pointed at this one.

Questions and answers

Do I need -X POST in curl?

No. Curl switches to POST on its own when you pass -d or --data. Adding -X POST is harmless but unnecessary.

Why does my streamed curl output arrive all at once?

Curl buffers by default. Add -N (or --no-buffer) so each data: line prints as it arrives.

How do I send a long prompt without hitting shell limits?

Put the JSON in a file and send it with -d @body.json. The request body can be up to 8 MB.

What should I do after a 429 response?

Check the error code. rate_limited means too many requests per minute, concurrency means too many at once, and a Retry-After: 5 header means wait five seconds and retry.

Your key is one form away

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

Get API key