Backport: feat (provider/gateway): add get-generation support#13870
Merged
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from Mar 27, 2026
Merged
Backport: feat (provider/gateway): add get-generation support#13870vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from
vercel-ai-sdk[bot] merged 1 commit intorelease-v6.0from
Conversation
## 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)
4 tasks
shaper
approved these changes
Mar 27, 2026
Contributor
Author
|
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an automated backport of #13842 to the release-v6.0 branch. FYI @shaper