Skip to content

feat(provider/google-vertex): allow overriding Vertex Anthropic auth token generation#14857

Merged
R-Taneja merged 5 commits intomainfrom
vertex-anthropic-generate-auth-token-option
Apr 30, 2026
Merged

feat(provider/google-vertex): allow overriding Vertex Anthropic auth token generation#14857
R-Taneja merged 5 commits intomainfrom
vertex-anthropic-generate-auth-token-option

Conversation

@R-Taneja
Copy link
Copy Markdown
Contributor

@R-Taneja R-Taneja commented Apr 30, 2026

Background

Today `createVertexAnthropic` (edge and node variants) unconditionally performs an OAuth exchange to mint a Bearer token before each request. Useful default — but there are real cases where you want to skip it:

  • Tests that don't want to spin up OAuth machinery
  • Custom auth providers that mint tokens differently (on-prem token exchange, etc.)
  • Proxy / relay scenarios where the caller already has a token to forward

Change

Adds an optional `generateAuthToken` setting to `GoogleVertexAnthropicProviderSettings` on both edge and node variants. When provided, the SDK calls it in place of the default OAuth flow. When omitted, behavior is identical to today.

createVertexAnthropic({
  project: '...',
  location: '...',
  generateAuthToken: async () => myCustomToken(),
});

Tests

Added one test per variant asserting that:

  • A custom `generateAuthToken` produces the right `Authorization` header
  • The default OAuth path is not called when the override is present

All existing anthropic tests still pass.

Risk

Purely additive. New optional field, default unchanged. No breaking changes.

…token generation

Adds an optional `generateAuthToken` setting to `createVertexAnthropic`
(both edge and node variants). When provided, the SDK calls this function
instead of performing the default OAuth exchange. Default behavior is
unchanged.

Useful for tests, custom auth providers, and proxy/relay scenarios where
the caller supplies the auth token directly.
@R-Taneja R-Taneja added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 30, 2026
@R-Taneja R-Taneja marked this pull request as ready for review April 30, 2026 18:32
@R-Taneja R-Taneja merged commit 780e563 into main Apr 30, 2026
18 checks passed
@R-Taneja R-Taneja deleted the vertex-anthropic-generate-auth-token-option branch April 30, 2026 18:57
github-actions Bot added a commit that referenced this pull request Apr 30, 2026
@github-actions github-actions Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ Backport PR created: #14861

github-actions Bot added a commit that referenced this pull request Apr 30, 2026
…opic auth token generation (#14861)

This is an automated backport of #14857 to the release-v6.0 branch. FYI
@R-Taneja

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: R-Taneja <47066511+R-Taneja@users.noreply.github.com>
gr2m pushed a commit that referenced this pull request Apr 30, 2026
…opic auth token generation (#14869)

Backport of #14857 to \`release-v5.0\`.

The v6 backport (#14861) is already merged. This brings the same change
to v5 so the option is available across all live branches the AI Gateway
depends on.

## Change

Adds optional \`generateAuthToken\` setting on \`createVertexAnthropic\`
(edge + node). When provided, the SDK uses it instead of the default
OAuth exchange. Default behavior unchanged.

\`\`\`ts
createVertexAnthropic({
  project: '...',
  location: '...',
  generateAuthToken: async () => myCustomToken(),
});
\`\`\`

## Tests

29 tests across edge + node, including merge order, fresh-call
semantics, error propagation, user-header override, and (node-only) null
return.

## Risk

Purely additive. No breaking changes.
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.0-beta.115
@ai-sdk/alibaba 2.0.0-beta.37
@ai-sdk/amazon-bedrock 5.0.0-beta.46
@ai-sdk/angular 3.0.0-beta.115
@ai-sdk/anthropic 4.0.0-beta.42
@ai-sdk/assemblyai 3.0.0-beta.32
@ai-sdk/azure 4.0.0-beta.42
@ai-sdk/baseten 2.0.0-beta.35
@ai-sdk/black-forest-labs 2.0.0-beta.31
@ai-sdk/bytedance 2.0.0-beta.32
@ai-sdk/cerebras 3.0.0-beta.35
@ai-sdk/cohere 4.0.0-beta.32
@ai-sdk/deepgram 3.0.0-beta.31
@ai-sdk/deepinfra 3.0.0-beta.35
@ai-sdk/deepseek 3.0.0-beta.33
@ai-sdk/elevenlabs 3.0.0-beta.31
@ai-sdk/fal 3.0.0-beta.31
@ai-sdk/fireworks 3.0.0-beta.35
@ai-sdk/gateway 4.0.0-beta.66
@ai-sdk/gladia 3.0.0-beta.31
@ai-sdk/google 4.0.0-beta.49
@ai-sdk/google-vertex 5.0.0-beta.63
@ai-sdk/groq 4.0.0-beta.34
@ai-sdk/huggingface 2.0.0-beta.35
@ai-sdk/hume 3.0.0-beta.31
@ai-sdk/klingai 4.0.0-beta.32
@ai-sdk/langchain 3.0.0-beta.115
@ai-sdk/llamaindex 3.0.0-beta.115
@ai-sdk/lmnt 3.0.0-beta.31
@ai-sdk/luma 3.0.0-beta.31
@ai-sdk/mcp 2.0.0-beta.37
@ai-sdk/mistral 4.0.0-beta.33
@ai-sdk/moonshotai 3.0.0-beta.35
@ai-sdk/open-responses 2.0.0-beta.33
@ai-sdk/openai 4.0.0-beta.42
@ai-sdk/openai-compatible 3.0.0-beta.35
@ai-sdk/otel 1.0.0-beta.61
@ai-sdk/perplexity 4.0.0-beta.34
@ai-sdk/prodia 2.0.0-beta.34
@ai-sdk/provider-utils 5.0.0-beta.30
@ai-sdk/react 4.0.0-beta.115
@ai-sdk/replicate 3.0.0-beta.32
@ai-sdk/revai 3.0.0-beta.32
@ai-sdk/rsc 3.0.0-beta.116
@ai-sdk/svelte 5.0.0-beta.115
@ai-sdk/togetherai 3.0.0-beta.35
@ai-sdk/valibot 3.0.0-beta.30
@ai-sdk/vercel 3.0.0-beta.35
@ai-sdk/voyage 1.0.0-beta.4
@ai-sdk/vue 4.0.0-beta.115
@ai-sdk/workflow 1.0.0-beta.30
@ai-sdk/xai 4.0.0-beta.48

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.

2 participants