EN ▾

unfilteredaiapi.comhttps://api.unfilteredaiapi.com/v1

Unfiltered AI

Raw, uncensored LLM API for developers.

Unfiltered AIGet API key

LLM API Response Empty? Causes and Fixes

When an llm api response empty error shows up, the server usually did answer and the empty string comes from how the reply is read. Here is a checklist, ordered by how often each cause turns up.

Data flowing through a glass pipe toward an empty speech bubble, with a lens revealing a hidden branch

Key points

  • Print the raw JSON first. Most empty replies are a parsing issue, not an outage.
  • Check finish_reason: length, stop and tool_calls each explain a blank content field.
  • In streams, read delta.content defensively and skip chunks with no choices.
  • A 429 or a proxy that buffers SSE can look like an empty answer in some clients.

Start by looking at the raw response

Before you change any settings, capture exactly what came back. Wrapper libraries hide the cause: a bare print(response.choices[0].message.content) shows None or an empty string whether the body was empty, held a tool call, ended on a length cap or never arrived.

Use curl so that no client code is in the way, and include the headers with -i:

curl -i https://api.unfilteredaiapi.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "uncensored",
    "messages": [{"role": "user", "content": "Say hello in five words."}]
  }'

Read three things in the result. First, the status line: 200 means a completion was produced, 429 means a limit was hit, an authentication error such as 401 usually points at the key. Second, choices[0].finish_reason. Third, the response headers, especially X-Request-Id (keep it if you contact support) and X-Balance-USD, which shows whether the account still has credit. If this curl call returns text, the service is working and the problem is in your client. If it returns an error body, you have the cause already.

Cause 1: the message holds a tool call, not text

If you pass tools and the model decides to call one, the assistant message has tool_calls and its content is null or empty. Code that only reads content sees a blank reply. The fix is to check for tool calls first, run the function, append the result as a message with role: "tool", and call the API again.

from openai import OpenAI

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

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "What is the weather in Oslo?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"],
            },
        },
    }],
)

msg = resp.choices[0].message
if msg.tool_calls:
    print("tool call:", msg.tool_calls[0].function.name, msg.tool_calls[0].function.arguments)
else:
    print(msg.content)

If you did not mean to offer tools, remove the tools and tool_choice fields. A leftover tool definition from an earlier experiment is a classic reason for blank text.

Cause 2: the reply was cut off or never started

finish_reason explains most of the rest.

  • length. The completion hit a token cap. You may have set max_tokens very low, such as 1 or 10. The parameter is optional here, since the completion can use whatever is left of the 100,000-token window, so the simplest fix is to drop it. If you need a cap, set it with room to spare.
  • stop. The model finished normally, or it produced one of your stop strings. A stop sequence like a newline stops the reply at the first line break, which can leave you with nothing if the model begins with a blank line. Remove or loosen the sequence.
  • tool_calls. See the previous section.

Context overflow is the other length problem. The window is 100,000 tokens, counting prompt and completion together. If a chat history has grown to nearly fill it, there is almost no room left to answer. Trim old turns or summarise them. The page on conversation memory and the long context window shows ways to keep history under control. A request body also cannot exceed 8 MB.

One more small trap: JSON mode. With response_format set to json_object, include the word JSON in your instructions and describe the shape you want. A vague prompt plus JSON mode produces thin or trivial output that looks empty once you pull a key out of it.

Cause 3: streaming is read wrongly

Streaming over SSE sends many small chunks. Not every chunk carries text. The first chunk often has only the role, the last content chunk carries a finish_reason with an empty delta, and the final chunk that reports usage can arrive with an empty choices list. Code that indexes choices[0] on every chunk will crash, and code that treats a chunk without text as the whole answer will print nothing.

from openai import OpenAI

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

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Write two sentences about rain."}],
    stream=True,
)

parts = []
for chunk in stream:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    if delta.content:
        parts.append(delta.content)

text = "".join(parts)
print(text if text else "[no content received]")

Two environment issues also look like empty streams. A reverse proxy or CDN that buffers responses will hold all chunks until the end, so a browser sees nothing for a long time and then everything at once, or a timeout fires first. Turn off response buffering for the streaming route in your proxy. And a stream occupies its concurrency slot until it ends, so abandoned streams (a closed tab, a missing close()) will gradually use up your 8 slots. The next request then gets a 429 rather than text. For a full server example, see the FastAPI backend with SSE streaming.

Cause 4: an error that your client swallowed

Some HTTP wrappers return an empty string on a non-200 status instead of raising. Log the status code and body for every failure. The cases that matter:

Status or codeMeaningWhat to do
429, rate_limitedMore than 300 requests per minute on a full key (60 on trial)Slow down, add a queue
429, concurrencyMore than 8 requests at once on a full key (2 on trial)Cap your workers
429 with Retry-After: 5Temporary overloadWait 5 seconds and retry
401Typically a missing or wrong keyCheck the Authorization: Bearer header
404Typically a wrong path or base URLBase URL must end at /v1

A simple retry wrapper takes a few lines and removes a whole class of sporadic blanks:

import time
from openai import OpenAI, RateLimitError

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

def ask(messages, tries=4):
    for attempt in range(tries):
        try:
            r = client.chat.completions.create(model="uncensored", messages=messages)
            return r.choices[0].message.content or ""
        except RateLimitError as e:
            wait = 5
            retry_after = getattr(e.response, "headers", {}).get("retry-after")
            if retry_after:
                wait = int(retry_after)
            time.sleep(wait)
    raise RuntimeError("still limited after retries")

Failed or refused requests are not charged, so a retry loop does not cost you twice. You can confirm by comparing X-Balance-USD before and after a failing call.

Cause 5: the wrong endpoint, model or key

A short checklist of configuration mistakes that produce odd results rather than loud errors:

  1. The base URL is https://api.unfilteredaiapi.com/v1. A missing /v1 or a doubled one can give a 404 body that a lenient client turns into an empty reply.
  2. The model name is uncensored, spelled exactly. Setting a model from another provider's catalogue is a common copy-paste slip.
  3. Only POST /v1/chat/completions and GET /v1/models exist. The legacy completions endpoint, embeddings and image routes are not available, so a library calling them gets nothing useful back.
  4. The key is sent as a Bearer token and has no stray whitespace or quotes from an env file.

Call GET /v1/models with your key as a connectivity test. If it lists the model, base URL and key are right and the problem is in the request body. The quickstart has the minimal working request to compare against, and the FAQ covers access, limits and billing.

Logging that shortens the next incident

Empty replies are hard to debug after the fact because nobody recorded what the server sent. A few lines of logging turn a mystery into a lookup.

  1. Log the X-Request-Id response header with every call, successful or not.
  2. Log finish_reason, the usage counts and the length of the returned text.
  3. For streams, log how many chunks arrived and how many carried text. Zero chunks with text and a normal finish points at your parser. Zero chunks at all points at the network or the proxy.
  4. Alert on the ratio of empty replies to total calls, not on single events. One blank in a thousand is noise. Five percent is a bug.

When you compare a failing call with a working one, diff the request bodies first. A changed system prompt, an added stop list, a smaller max_tokens or a swapped model name explains most regressions. Put the request body in the log for a sample of calls, after removing any personal data.

If several users report blanks at the same time and your curl test also fails, the cause is probably not your code. Check for a 429 with Retry-After first, since temporary overload is signalled that way, and retry after the stated delay. If the curl test works and your app fails, work from the client side using the sections above.

If the reply is short rather than empty

Sometimes the symptom is a one-line answer where you wanted a page. That is a prompting problem more than a transport one. Ask for the length and form you want ("at least 400 words, in three paragraphs"), put the instruction in the system message, and raise temperature a little if the model is being terse. The model is tuned to answer without content refusals for lawful adult use, so a short reply is rarely a refusal; it is more often an under-specified request. Sexual content involving minors is the one hard limit and is always declined.

Still stuck? Send support the X-Request-Id from the failing response, the approximate time, and the request body without your key. That lets someone find the exact call. If you are new to the service, the key page has the trial credit claim, which is enough for dozens of debugging calls.

Questions and answers

Why is message.content null?

Most often the model returned tool_calls instead of text, or the stream was read incorrectly. Check finish_reason and tool_calls on the message before treating it as an error.

Does an empty response cost money?

Failed or refused requests are not charged. If a call succeeded and produced tokens you will see usage counts, and X-Balance-USD in the headers shows your balance.

Can a full context window cause blank output?

Yes. Prompt and completion share 100,000 tokens, so a nearly full history leaves little or no room for the answer. Trim or summarise earlier turns.

Why does my stream show nothing, then everything at once?

A proxy or CDN is probably buffering the SSE response. Disable buffering for that route so chunks pass through as they arrive.

Your key is one form away

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

Get API keyRead the docs