Esc

This model's maximum context length is N tokens

The request is longer than the model can hold. Your prompt, the whole conversation history and the space reserved for the answer all count. The history is usually the culprit, not the prompt.

Tested on GPT-5 ·

AI Place Hub 75
PromptCopied
This model's maximum context length is 128000 tokens. However, your messages resulted in 131515 tokens. Please reduce the length of the messages.

The number in the message is the total budget. It is no limit on your message alone. Three things share it: everything you sent, everything the model already said in this conversation, and the room set aside for the reply.

The usual cause is a chat loop that appends every turn and never trims. It works for twenty messages and fails on the twenty-first, which is why it looks sudden.

Notes from the author

Check the history first. Print the token count of what you actually send, not what you believe you send. In most failing scripts the system prompt and the last user message are small and the accumulated history is huge.

Then reserve output space. With max_tokens at 4000 and a limit of 128000, your input has to fit in 124000. Forget this and you get the same error at a length that looks like it should fit.

Then trim. Keep the system prompt and the last few exchanges, squeeze the middle into a few lines and drop the rest. A rolling summary beats cutting from the front, which throws away the decisions the conversation was built on.

On Ollama the cause differs. The error looks the same but the culprit is usually num_ctx, which defaults low whatever the model supports. Set it in the Modelfile instead of trimming a document that would have fitted.

For information only, not professional advice. You use it at your own risk and we are not liable for any loss or damage. See the disclaimer.

Fork

Did this work for you?

Sign in to flag it

Related

  • CheatsheetClaude

    Claude Code commands worth knowing

    The slash commands that save the most time, from your first CLAUDE.md to reviewing a diff before it ships.

    Tested on Claude Sonnet · Sep 2026

    Coding0045AI Place Hub
  • CheatsheetChatGPT

    ChatGPT commands for the desktop app

    The composer slash commands in the ChatGPT desktop app: switching models, running a review, and working in the cloud or in a git worktree.

    Tested on GPT-5 · Sep 2026

    Coding0043AI Place Hub
  • ToolUniversalSERVICEUsage-based, pay per second of compute

    Replicate

    Run thousands of community-published models, image, audio, video and language, behind one API without hosting any of them yourself.

    Tested on GPT-5 · Jun 2026

  • ToolUniversalCLIFree, open source; you pay only for the API you connect

    Aider

    A terminal pair programmer that edits files straight in your working tree and commits each change with a generated message. No copy-paste loop.

    Tested on Claude Sonnet · Jun 2026

    Coding0046AI Place Hub