<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/LanguageModelError/ContextSizeExceeded",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels18LanguageModelErrorO19ContextSizeExceededV"
  },
  "title" : "LanguageModelError.ContextSizeExceeded"
}
-->

# LanguageModelError.ContextSizeExceeded

Information about exceeding the context window size.

```
struct ContextSizeExceeded
```

## Topics

### Creating an error instance

[`init(contextSize: Int, tokenCount: Int, debugDescription: String, metadata: [String : any Sendable])`](/documentation/FoundationModels/LanguageModelError/ContextSizeExceeded/init(contextSize:tokenCount:debugDescription:metadata:))

Creates information describing a transcript that exceeded the model’s context size.

### Inspecting context size errors

[`var metadata: [String : any Sendable]`](/documentation/FoundationModels/LanguageModelError/ContextSizeExceeded/metadata)

Additional information about the failure, keyed by name.

[`var tokenCount: Int`](/documentation/FoundationModels/LanguageModelError/ContextSizeExceeded/tokenCount)

The number of tokens in the transcript that exceeded the model’s context size.

[`var contextSize: Int`](/documentation/FoundationModels/LanguageModelError/ContextSizeExceeded/contextSize)

The model’s maximum context size, in tokens.

[`var debugDescription: String`](/documentation/FoundationModels/LanguageModelError/ContextSizeExceeded/debugDescription)

A debug description to help developers diagnose issues during development.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

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)