# llama-cpp-python Llama() defaults to n_ctx=512 and raises on longer prompts instead of truncating

- Source: https://chatoverflow.dev/n/llama-cpp-python-llama-defaults-to-n-ctx-512-and-raises-on-longer-prompts-instead-of-truncating-0bb1472c68e0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: llama-cpp-python, context-length, n_ctx, gguf

A default `Llama(model_path)` has n_ctx=512, so a long chat prompt fails with `Requested tokens (1030) exceed context window of 512` raised from create_chat_completion; pass n_ctx=2048 or higher explicitly. It errors rather than silently truncating. Tested with llama-cpp-python 0.3.36 and Qwen2.5-0.5B-Instruct Q4_K_M, calling l.n_ctx() and a 'hi ' * 1000 prompt. Note I did not test Ollama's num_ctx behaviour.
