EN ▾
Get API key

NSFW API curl Example: Your First Request

Here is a working NSFW API curl example you can paste into a terminal: one request to list models, one to chat, then streaming, JSON mode and tool calling. Only your key changes.

Updated

Isometric illustration of a terminal sending a stream of light particles into a chat bubble, a curl request to an LLM API

Key points

  • Two endpoints: GET /v1/models and POST /v1/chat/completions, with a Bearer key and the model ID uncensored.
  • Add -N and stream: true to see SSE chunks; add response_format for JSON mode; add tools for function calls.
  • Use curl -i to read X-Balance-USD, X-Request-Id and the rate limit headers.
  • A 429 means slow down: rate_limited, concurrency, or a short overload with Retry-After: 5.

Set up the key and base URL

This NSFW API curl example assumes you already have a key. If not, sign up and claim the $0.50 trial credit from the API key page; it takes one click. Then keep the key in an environment variable so it never lands in your shell history or a script you commit.

export API_KEY="paste-your-key-here"
export BASE="https://api.nsfwapi.top/v1"

The API follows the OpenAI request format, which means every OpenAI SDK and most clients work after you change two values: the base URL and the key. The model ID is uncensored. Authentication is a standard header, Authorization: Bearer <key>. Two methods exist: POST /v1/chat/completions for chat and GET /v1/models for listing models.

The model behind it is one open-weight 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 big vendor and it is not a router across several. It generates text only. Everything below is plain HTTP, so it also works from any language that can send a POST request.

Request 1: list the models

Start with the cheapest call that proves your key and URL are right. Listing models costs nothing in tokens.

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

You should get a JSON object with a data array that includes the id uncensored. If you get HTTP 401, the key is wrong or missing the word Bearer. If curl cannot connect, check the URL for a typo; the path is /v1/models under the host api.nsfwapi.top.

Request 2: your first chat completion

Now the main call. This sends a system message and a user message and caps the reply length.

curl -s "$BASE/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You are a concise fiction co-writer for adults."},
      {"role": "user", "content": "Give me three opening lines for a heist story."}
    ],
    "temperature": 0.8,
    "max_tokens": 200
  }'

The reply is a standard chat completion object. The text sits at choices[0].message.content, and the usage block reports prompt and completion tokens. If you have jq installed, pipe the output through it to see only the text:

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

That second request has no max_tokens. It is optional: the completion may use whatever is left of the 100,000-token window, which covers prompt and completion together. For real use, set a limit anyway so a runaway answer cannot cost more than you planned. Sampling settings such as temperature, top_p, stop, seed and the penalties are passed through to the model.

Read the response headers

Add -i to see headers along with the body. Four of them are useful in practice.

curl -i "$BASE/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"uncensored","messages":[{"role":"user","content":"Ping."}],"max_tokens":5}'
HeaderWhat it tells you
X-Request-IdAn ID for this call. Include it if you contact support.
X-Balance-USDYour remaining prepaid balance.
X-RateLimit-Limit-RequestsRequests per minute allowed on this key.
X-RateLimit-Limit-ConcurrencySimultaneous requests allowed on this key.

To see what a call costs, compare the balance before and after. A tiny request like the one above, around 40 input tokens and 10 output tokens, costs about $0.000011: 40 times $0.15 divided by 1,000,000 is $0.000006, and 10 times $0.50 divided by 1,000,000 is $0.000005. Failed or refused requests are not charged, so a request that returns an error leaves the balance as it was.

Streaming with curl

Set "stream": true and tell curl not to buffer with -N. The server answers with server-sent events, one data: line per chunk, and ends with data: [DONE]. Token usage arrives at the end of the stream.

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

Each chunk carries a small delta with a few characters in choices[0].delta.content. Without -N curl waits for its buffer to fill and you see everything at once, which looks like streaming is broken when it is not.

Streaming has one operational detail that matters. A streamed request occupies its concurrency slot until the stream ends. A trial key has 2 slots and a full key has 8, so if you open a stream in a terminal and leave it hanging, you are using one of them.

JSON mode and tool calling

For structured output, set response_format to a JSON object and say in the prompt that you want JSON. The word is a useful nudge even though the parameter does the enforcing.

curl -s "$BASE/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 a JSON object with keys name, tone and hook for a villain character."}
    ]
  }'

Tool calling uses the same shape as the OpenAI API. You describe functions in tools, optionally force a choice with tool_choice, and read tool_calls from the reply. Streamed responses deliver tool_calls in pieces.

curl -s "$BASE/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 next scene."}],
    "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"
  }'

When the model decides to call the function, message.tool_calls[0].function.arguments holds a JSON string such as {"sides": 20}. Run the function yourself, then send a second request that repeats the earlier messages, adds the assistant message with its tool_calls, and adds your result as a message with "role": "tool" and the matching tool_call_id. The model then writes the final answer.

Keep a conversation going

The endpoint is stateless. It does not remember the last call, so a follow-up question only works if you send the earlier turns again. In curl that means adding the assistant's previous reply to the messages array and then the new user message.

curl -s "$BASE/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You are a concise fiction co-writer for adults."},
      {"role": "user", "content": "Give me a name for a ship captain."},
      {"role": "assistant", "content": "Captain Isolde Venn."},
      {"role": "user", "content": "Now give her a secret."}
    ],
    "max_tokens": 120
  }'

The model sees all four messages and answers the last one with the earlier context in mind. Every call bills the full input again, so a long thread costs more per turn than a short one. At $0.15 per 1M input tokens that is still small: a 10,000-token history adds $0.0015 to each call. Past a certain length, replace the oldest turns with a short summary instead of sending them forever.

Use the system message for rules that must hold for the whole session, such as tone, format and the limits of your own app. Put one-off instructions in the user message so they do not leak into later turns.

The same call in Python and Node

curl is for testing. In an application you will use an SDK, and the move is mechanical because the format is identical. Only the base URL, the key and the model name differ from an OpenAI setup.

from openai import OpenAI

client = OpenAI(base_url="https://api.nsfwapi.top/v1", api_key="YOUR_KEY")

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Give me three opening lines for a heist story."}],
    max_tokens=200,
)
print(resp.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.nsfwapi.top/v1",
  apiKey: process.env.API_KEY,
});

const resp = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Give me three opening lines for a heist story." }],
  max_tokens: 200,
});
console.log(resp.choices[0].message.content);

If a curl command works and the SDK version does not, compare three things: the base URL must end in /v1, the model must be uncensored, and the key must be the one from your account. Those account for nearly every first-run failure. Print the raw HTTP status when in doubt; the SDKs raise errors with the same 401 and 429 codes described below.

Common errors and what to do

  • 401: bad or missing key. Check for a stray space or newline in the variable, and the word Bearer in the header.
  • Oversized requests: the maximum body is 8 MB, and the prompt plus completion must fit the 100,000-token window, so trim long histories.
  • 429 with rate_limited: too many requests in a minute. A trial key allows 60 and a full key 300.
  • 429 with concurrency: too many requests at once. A trial key allows 2 and a full key 8. Wait for earlier requests, or streams, to finish.
  • 429 with Retry-After: 5: temporary overload. Wait five seconds and send the call again.

In a shell loop, a simple retry for the last case is sleep 5 between attempts and a limit of three tries. Do not hammer the endpoint in a tight loop; the limits above apply per key.

When the tests pass, move to a real client. Because the format matches OpenAI, the Python and Node SDKs need only base_url and api_key changed, and the documentation has the full parameter list. Costs for any volume you plan are worked out on the pricing page: $0.15 per 1M input tokens, $0.50 per 1M output tokens, prepaid, with a 100,000-token context. For a wider look at when an uncensored model fits a project, read cost and trade-offs.

Questions and answers

What is the base URL for the curl commands?

https://api.nsfwapi.top/v1. Chat requests go to /chat/completions and the model list is at /models, both with an Authorization: Bearer header.

Why does streaming print everything at once in curl?

curl buffers output by default. Add the -N flag so each server-sent event is shown as it arrives.

Can I test without paying?

Yes. New users can claim $0.50 of trial credit with one click on the API key page. It is valid for 7 days with no payment details.

Does the API support function calling?

Yes. Pass tools and tool_choice as in the OpenAI API, read tool_calls from the reply, and send results back as role tool messages.

What does a 429 response mean?

You hit a limit or the service is briefly overloaded. The error code is rate_limited or concurrency, or the response has a Retry-After: 5 header. Wait 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