Skip to content

Backport: feat (provider/gateway): add get-generation support#13870

Merged
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from
backport-pr-13842-to-release-v6.0
Mar 27, 2026
Merged

Backport: feat (provider/gateway): add get-generation support#13870
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from
backport-pr-13842-to-release-v6.0

Conversation

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

@vercel-ai-sdk vercel-ai-sdk Bot commented Mar 27, 2026

This is an automated backport of #13842 to the release-v6.0 branch. FYI @shaper

## Background

The AI Gateway provider was missing the ability to look up detailed information about specific generations after they were created. Users needed a way to retrieve cost, token usage, latency, and provider details for individual generations using their IDs.

## Changes

This PR adds generation lookup functionality to the AI Gateway provider:

- **New `getGenerationInfo()` method**: Allows fetching detailed information about a specific generation by its ID
- **Generation ID access**: Generation IDs are now available in `providerMetadata.gateway.generationId` on both `generateText` and `streamText` responses
- **Comprehensive generation data**: Returns cost breakdown, token usage, latency metrics, provider details, and more
- **Error handling**: Proper error handling for authentication, server errors, and malformed responses
- **Documentation**: Added complete documentation with examples showing how to use the new functionality
- **Example implementation**: Added a working example demonstrating the feature

The `getGenerationInfo()` method returns detailed information including:
- Cost breakdown (total cost, upstream inference cost for BYOK)
- Token usage (prompt, completion, reasoning, cached tokens)
- Performance metrics (latency, generation time)
- Provider and model information
- Generation metadata (streaming, finish reason, etc.)

## Manual Verification

Tested the feature by:
1. Making a generation request with the gateway provider
2. Extracting the generation ID from the provider metadata
3. Using `getGenerationInfo()` to fetch detailed generation information
4. Verifying all returned fields contain expected data types and values
5. Testing error scenarios (invalid IDs, authentication failures)

## Checklist

- [x] Tests have been added / updated (for bug fixes / features)
- [x] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)
@vercel-ai-sdk vercel-ai-sdk Bot enabled auto-merge (squash) March 27, 2026 07:10
@tigent tigent Bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label documentation Improvements or additions to documentation feature New feature or request provider/gateway Issues related to the @ai-sdk/gateway provider labels Mar 27, 2026
@vercel-ai-sdk vercel-ai-sdk Bot merged commit 768a9d6 into release-v6.0 Mar 27, 2026
26 checks passed
@vercel-ai-sdk vercel-ai-sdk Bot deleted the backport-pr-13842-to-release-v6.0 branch March 27, 2026 16:11
@shaper shaper added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 27, 2026
vercel-ai-sdk Bot added a commit that referenced this pull request Mar 27, 2026
@vercel-ai-sdk vercel-ai-sdk Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Mar 27, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor Author

vercel-ai-sdk Bot commented Mar 27, 2026

⚠️ Backport to release-v5.0 created but has conflicts: #13881

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor Author

vercel-ai-sdk Bot commented Mar 27, 2026

🚀 Published in:

Package Version
ai 6.0.141
@ai-sdk/angular 2.0.142
@ai-sdk/gateway 3.0.83
@ai-sdk/langchain 2.0.147
@ai-sdk/llamaindex 2.0.141
@ai-sdk/react 3.0.143
@ai-sdk/rsc 2.0.141
@ai-sdk/svelte 4.0.141
@ai-sdk/vue 3.0.141

gr2m added a commit that referenced this pull request Apr 16, 2026
…rt (#13881)

This is an automated backport of #13870 to the release-v5.0 branch.

---------

Co-authored-by: vercel-ai-sdk[bot] <225926702+vercel-ai-sdk[bot]@users.noreply.github.com>
Co-authored-by: open-agents-bot[bot] <260704009+open-agents-bot[bot]@users.noreply.github.com>
Co-authored-by: gr2m <39992+gr2m@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label documentation Improvements or additions to documentation feature New feature or request provider/gateway Issues related to the @ai-sdk/gateway provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant