feat (provider/gateway): add get-generation support#13842
Merged
Conversation
Collaborator
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
4 tasks
felixarntz
approved these changes
Mar 26, 2026
6f6e9bf to
fdaacea
Compare
b14d7ed to
5464080
Compare
5464080 to
7bc628c
Compare
7bc628c to
6d9113b
Compare
d574905 to
f01df16
Compare
f01df16 to
d30466c
Compare
6d9113b to
4a68f65
Compare
4a68f65 to
2fd9eab
Compare
vercel-ai-sdk bot
pushed a commit
that referenced
this pull request
Mar 27, 2026
## 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)
Contributor
|
✅ Backport PR created: #13870 |
Contributor
|
🚀 Published in:
|
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.

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:
getGenerationInfo()method: Allows fetching detailed information about a specific generation by its IDproviderMetadata.gateway.generationIdon bothgenerateTextandstreamTextresponsesThe
getGenerationInfo()method returns detailed information including:Manual Verification
Tested the feature by:
getGenerationInfo()to fetch detailed generation informationChecklist
pnpm changesetin the project root)