Skip to content

Add betas parameter for per-request beta feature opt-in#16

Merged
mozex merged 1 commit intomainfrom
beta-features
Apr 18, 2026
Merged

Add betas parameter for per-request beta feature opt-in#16
mozex merged 1 commit intomainfrom
beta-features

Conversation

@mozex
Copy link
Copy Markdown
Owner

@mozex mozex commented Apr 18, 2026

Adds a first-class betas parameter that any resource method accepts and converts into a per-request anthropic-beta header. Lets us enable beta features without forcing users to manually set the header on the factory.

$response = $client->messages()->create([
    'model' => 'claude-opus-4-6',
    'max_tokens' => 1024,
    'messages' => [...],
    'betas' => ['extended-cache-ttl-2025-04-11'],
]);

The SDK strips betas out of the parameters before serialization, so nothing leaks into the JSON body or the query string. It becomes a comma-separated anthropic-beta header on that one request only.

Key behaviors

  • Extraction, not pass-through. betas is the one parameter that's actively consumed by the SDK. Factory methods on Payload (create, list, retrieve, modify, upload) pull it out; the request body never contains it.
  • Auto-injection for resources. A new Payload::withBetas(array) method lets resources inject the beta they require (e.g. a future Files::upload() will add files-api-2025-04-14 automatically). Users don't have to type the version string for resources they're already calling.
  • Global + per-request merge. If you set anthropic-beta via withHttpHeader() and also pass betas: [...] on a call, the request sends both, de-duplicated in order of appearance.
  • Non-string entries filtered out. betas: ['files-api-2025-04-14', 42, null, ''] sends just the one valid string.
  • Empty array is a no-op. No anthropic-beta header is added if betas is present but empty.

@mozex mozex merged commit a2a95df into main Apr 18, 2026
28 checks passed
@mozex mozex deleted the beta-features branch April 18, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant