<!--
{
  "availability" : [
    "iOS: 26.0.0 - 27.0.0",
    "iPadOS: 26.0.0 - 27.0.0",
    "macCatalyst: 26.0.0 - 27.0.0",
    "macOS: 26.0.0 - 27.0.0",
    "visionOS: 26.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/LanguageModelSession/GenerationError/exceededContextWindowSize(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "Foundation Models"
    ],
    "preciseIdentifier" : "s:16FoundationModels20LanguageModelSessionC15GenerationErrorO25exceededContextWindowSizeyA2E0I0VcAEmF"
  },
  "title" : "LanguageModelSession.GenerationError.exceededContextWindowSize(_:)"
}
-->

# LanguageModelSession.GenerationError.exceededContextWindowSize(_:)

An error that signals the session reached its context window size limit.

```
case exceededContextWindowSize(LanguageModelSession.GenerationError.Context)
```

## Discussion

This error occurs when you use the available tokens for the context window of 4,096 tokens. The
token count includes instructions, prompts, and outputs for a session instance. A single token
corresponds to approximately three to four characters in languages like English, Spanish, or
German, and one token per character in languages like Japanese, Chinese, and Korean.

Start a new session when you exceed the content window size, and try again using a shorter
prompt or shorter output length.

For more information on managing the context window size,
see [Managing the context window](/documentation/FoundationModels/managing-the-context-window).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)