{"slug": "apple-foundation-models", "title": "Apple Foundation Models", "summary": "Anthropic released Claude for Foundation Models, a Swift package that integrates Claude as a server-side language model in Apple's Foundation Models framework, allowing developers to use Claude with the same API as Apple's on-device model. Requests go directly to the Claude API, bypassing Apple, and usage is billed to the user's Anthropic account. The package is in beta and targets the OS 27 betas.", "body_md": "We use cookies to deliver and improve our services, analyze site usage, and if you agree, to customize or personalize your experience and market our services to you. You can read our Cookie Policy [here](https://www.anthropic.com/legal/cookies).\n\n[Claude for Foundation Models](https://github.com/anthropics/ClaudeForFoundationModels) is a Swift package that makes Claude available as a server-side language model in Apple's [Foundation Models](https://developer.apple.com/documentation/foundationmodels) framework. The package conforms Claude to the framework's `LanguageModel`\n\nprotocol, so you drive it with the same `LanguageModelSession`\n\nAPI you use for Apple's on-device model: `respond(to:)`\n\n, streaming, guided generation, and tool calling all work the same way.\n\nRequests go directly from your app to the Claude API; Apple is not in the request path and does not see prompts or responses. Usage is billed to your Anthropic account at [standard API pricing](/docs/en/about-claude/pricing). Your app decides when to use Claude and when to use Apple's on-device model: pass whichever model you want to each session.\n\n**Beta.** This package targets the Foundation Models server-side language model API introduced in the OS 27 betas. APIs may change before general availability.\n\nClaude for Foundation Models is **not** a general-purpose Messages API client. Its public surface is the Foundation Models provider conformance plus the configuration types that reach it (`ClaudeLanguageModel`\n\n, `ClaudeModel`\n\n, `AuthMode`\n\n, `ClaudeServerTool`\n\n). For direct access to the Messages API in another language, see the [Client SDKs](/docs/en/cli-sdks-libraries/overview#client-sdks).\n\nAdd the package to your `Package.swift`\n\n:\n\n```\ndependencies: [\n  .package(url: \"https://github.com/anthropics/ClaudeForFoundationModels.git\", from: \"0.1.0\")\n]\n```\n\nOr in Xcode: **File** > **Add Package Dependencies…** and enter the repository URL.\n\nThen add `ClaudeForFoundationModels`\n\nto your target's dependencies and import it alongside `FoundationModels`\n\n:\n\n``` python\nimport FoundationModels\nimport ClaudeForFoundationModels\n```\n\n`ClaudeLanguageModel`\n\nis the entry point. Pass it to `LanguageModelSession`\n\nand use the session exactly as you would with any Foundation Models provider:\n\n``` python\nimport FoundationModels\nimport ClaudeForFoundationModels\n\nlet model = ClaudeLanguageModel(\n  name: .sonnet4_6,\n  auth: .apiKey(ProcessInfo.processInfo.environment[\"ANTHROPIC_API_KEY\"] ?? \"\")\n)\n\nlet session = LanguageModelSession(model: model)\nlet response = try await session.respond(to: \"Plan a 4-day trip to Buenos Aires.\")\nprint(response.content)\n```\n\nThe initializer also accepts `baseURL`\n\n(default `https://api.anthropic.com`\n\n), `timeout`\n\n, and `serverTools`\n\n(see [Server-side tools](#server-side-tools)).\n\nFor a complete working program, the repository includes [ Examples/ClaudeExample](https://github.com/anthropics/ClaudeForFoundationModels/tree/main/Examples/ClaudeExample), a runnable command-line target that streams a chat turn to the terminal, with a\n\n`--search`\n\nflag that enables server-side web search for the turn. Running it requires a macOS 27 host.Model identifiers are values of `ClaudeModel`\n\n. Use a compiled-in constant, or construct one with explicit capabilities for an ID that isn't compiled in yet (see [Capabilities](#capabilities)):\n\n```\nClaudeLanguageModel(name: .opus4_8, auth: auth)\n```\n\nConstants mirror API model IDs (`.opus4_8`\n\nis `claude-opus-4-8`\n\n) and carry each model's capabilities. New models ship as new constants in package releases; check `ClaudeModel`\n\nin Xcode for the current list, and the [Models overview](/docs/en/about-claude/models/overview) to compare models.\n\nEach `ClaudeModel`\n\ndeclares what it accepts: sampling parameters, effort levels, adaptive thinking, structured output, and image input. The package uses this to decide which request fields to send, because sending a field a model rejects is a hard error. The constants carry the right capabilities. For an ID that isn't compiled in, declare what the model accepts (there is deliberately no shorthand that guesses):\n\n``` js\nlet model = ClaudeModel(\n  id: \"claude-experimental-x\",\n  capabilities: .init(samplingParams: false, effortLevels: [.low, .high])\n)\nClaudeLanguageModel(name: model, auth: auth)\n```\n\nPin a Claude [effort level](/docs/en/build-with-claude/effort) for every request with `fixedEffort:`\n\n. It takes precedence over the framework's per-request reasoning hints, and it's the only way to request `.xhigh`\n\nor `.max`\n\n, because the framework's reasoning levels stop at high. The API defaults to `high`\n\nwhen no effort is sent:\n\n```\nClaudeLanguageModel(name: .opus4_8, auth: auth, fixedEffort: .xhigh)\n```\n\nThe level must be one the model accepts. Each `ClaudeModel`\n\ndeclares which of the five levels (`low`\n\n, `medium`\n\n, `high`\n\n, `xhigh`\n\n, `max`\n\n) its model takes, if any: some models don't accept effort at all.\n\nApple's on-device model is fast, private, and works offline, but it is sized for lightweight tasks. Escalate to Claude when you need larger context, frontier reasoning, or server-side tools such as web search and code execution. Because both use the same `LanguageModelSession`\n\nAPI, you can switch by swapping the `model:`\n\nargument.\n\nSet the credential with the `auth:`\n\nparameter.\n\nPass an API key directly while developing:\n\n```\nClaudeLanguageModel(name: .sonnet4_6, auth: .apiKey(\"YOUR_API_KEY\"))\n```\n\nA key bundled into an app is extractable from the shipping binary, and anyone who extracts it can make requests billed to your account. Use `.apiKey`\n\nfor development only, and switch to a proxy before release.\n\nFor production, route requests through your own back end with `.proxied`\n\n. The relay at `baseURL`\n\nadds the Claude API credential server-side, so the app ships no key. The `headers`\n\nyou provide are sent on every request so your proxy can authorize the caller. Pass `[:]`\n\nif it needs none:\n\n```\nClaudeLanguageModel(\n  name: .sonnet4_6,\n  auth: .proxied(headers: [\"X-App-Token\": \"...\"]),\n  baseURL: URL(string: \"https://api.yourapp.com/claude\")!\n)\n```\n\nYour proxy receives standard [Messages API](/docs/en/api/messages/create) requests, attaches the `x-api-key`\n\nheader, and forwards them to `https://api.anthropic.com`\n\n.\n\n`streamResponse(to:)`\n\nreturns the response incrementally. Each element is a cumulative snapshot of the response so far, not a delta:\n\n``` js\nlet stream = session.streamResponse(to: \"Summarize today's top science stories.\")\nfor try await partial in stream {\n  print(partial.content)\n}\n```\n\nAnnotate a type with `@Generable`\n\nand request it with `generating:`\n\n. The model returns a value of that type through [structured outputs](/docs/en/build-with-claude/structured-outputs):\n\n``` js\n@Generable\nstruct Trip {\n  @Guide(description: \"Destination city\") var destination: String\n  @Guide(description: \"Length in days\") var days: Int\n}\n\nlet response = try await session.respond(to: \"Plan a trip to Tokyo.\", generating: Trip.self)\nprint(response.content.destination)\n```\n\nStructured output requires a model whose capabilities include it (all compiled-in constants do). If the chosen model does not, the package throws `LanguageModelError.unsupportedGenerationGuide`\n\nrather than silently degrading.\n\nThe framework's `tools:`\n\narray works unchanged. Conform your types to `Tool`\n\n, pass them to `LanguageModelSession`\n\n, and the framework invokes them on the device when Claude calls them. See [Tool use with Claude](/docs/en/agents-and-tools/tool-use/overview).\n\n``` js\nlet session = LanguageModelSession(model: model, tools: [FindRestaurantsTool()])\n```\n\n[Server tools](/docs/en/agents-and-tools/tool-use/server-tools) (web search, web fetch, and code execution) run on Anthropic's infrastructure within a single round trip, with nothing for the framework to invoke on the device. Configure them per model with `serverTools:`\n\n:\n\n``` js\nlet model = ClaudeLanguageModel(\n  name: .sonnet4_6,\n  auth: auth,\n  serverTools: [\n    .webSearch(maxUses: 5),\n    .codeExecution,\n  ]\n)\n```\n\n`.webSearch`\n\nand `.webFetch`\n\naccept optional `allowedDomains`\n\n, `blockedDomains`\n\n, and `maxUses`\n\n. Server tool activity surfaces in the transcript as `ClaudeServerToolSegment`\n\ncustom segments.\n\n`serverTools`\n\nis configured on `ClaudeLanguageModel`\n\nrather than on `LanguageModelSession`\n\nbecause the session type is Apple's. To use different server-tool sets per conversation, construct multiple `ClaudeLanguageModel`\n\ninstances.\n\nModels whose capabilities include image input declare the framework's vision capability. Pass image content through the framework's standard session API; the package converts it to the Claude API's image format. See [Vision](/docs/en/build-with-claude/vision) for image requirements.\n\nThe package maps Claude API errors onto Apple's `LanguageModelError`\n\ncases where one fits: context-window overflow surfaces as `.contextSizeExceeded`\n\n, HTTP 429 as `.rateLimited`\n\n, a request past the configured timeout as `.timeout`\n\n. Provider errors with no framework equivalent surface as `ClaudeError`\n\n. Pattern-match to drive product flows:\n\n``` js\ndo {\n  let response = try await session.respond(to: prompt)\n  print(response.content)\n} catch ClaudeError.missingCredential {\n  // Prompt for an API key.\n} catch let error as LanguageModelError {\n  // Framework-shaped errors (rate limits, guardrails, context length, decoding).\n} catch {\n  // Transport errors.\n}\n```\n\nA common pattern is to catch `.rateLimited`\n\nand fall back to `SystemLanguageModel`\n\nfor that turn, queue the request, or surface a retry affordance.\n\nThe package surfaces the Messages API capabilities that the Foundation Models provider protocol can express. Features with no representation in Apple's protocol are not available through it, including:\n\n| Reference | Covers |\n|---|---|\n|\n\n`LanguageModelSession`\n\n, `@Generable`\n\n, `Transcript`\n\n, `Tool`\n\n, and the rest of the framework surface`ClaudeForFoundationModels`\n\non GitHubThe package is licensed under Apache 2.0. Bug reports are welcome through GitHub issues. External pull requests are not being accepted during the beta period.\n\nWas this page helpful?", "url": "https://wpnews.pro/news/apple-foundation-models", "canonical_source": "https://platform.claude.com/docs/en/cli-sdks-libraries/libraries/apple-foundation-models", "published_at": "2026-06-15 04:55:34+00:00", "updated_at": "2026-06-15 05:12:26.069306+00:00", "lang": "en", "topics": ["large-language-models", "developer-tools", "ai-products"], "entities": ["Anthropic", "Apple", "Claude", "Foundation Models", "Claude for Foundation Models", "Swift", "Xcode", "GitHub"], "alternates": {"html": "https://wpnews.pro/news/apple-foundation-models", "markdown": "https://wpnews.pro/news/apple-foundation-models.md", "text": "https://wpnews.pro/news/apple-foundation-models.txt", "jsonld": "https://wpnews.pro/news/apple-foundation-models.jsonld"}}