Skip to content

Why is my chat request rejected even though it has few words?

The current chat contract limits combined message content to 12 KB measured as UTF-8 bytes, not a fixed word count. Non-ASCII text can use several bytes per character. The full JSON request also has a separate 20 KB envelope limit, and there may be at most 32 messages. Check all three rather than counting visible words alone.

BUILD NON-STREAMING TEXT WORKFLOWSAISwapLab team · Editorial methodPublished 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Measure the actual content; Remove unnecessary material; Validate the complete envelope.
Workflow diagram: Measure the actual content → Remove unnecessary material → Validate the complete envelope. Read the article for evidence and limits.

Characters, bytes and tokens measure different things

A short-looking multilingual prompt, escaped text or a large embedded data string can exceed a byte limit unexpectedly. These input-validation limits are not the model's advertised context window, and increasing max_tokens or max_credits does not override them. The service's quote input bound is also not an exact tokenizer count.

What to do next

  1. 01

    Measure the actual content

    Calculate UTF-8 byte length for every message and sum it. Exclude no message merely because its role is system or assistant; all content contributes to the limit.

  2. 02

    Remove unnecessary material

    Trim repeated history, raw documents and accidental base64 data. Keep the essential task requirements and distinguish summaries from source material when reducing context.

  3. 03

    Validate the complete envelope

    Serialize the final JSON body and check its total size and message count before quoting. Preserve that exact approved body for retries so later context expansion does not change it.

A concrete example

Illustrative failure: a request contains ten short-looking messages in a language whose characters use multiple UTF-8 bytes. It crosses the text-byte ceiling despite a modest visual character count. A byte measurement identifies the real restriction.

Before you call it ready

  • UTF-8 bytes are measured.
  • Message count and JSON size are checked separately.
  • No attachment data is hidden inside text.

When to stop or choose another method

If the task needs substantially more source material, divide it into meaningful supported steps or choose another service. Do not disguise oversized data as a single message.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation