Skip to content

feat (provider/gateway): add spend reporting support#13841

Merged
shaper merged 2 commits intomainfrom
03-25-feat_provider_gateway_add_spend_reporting_support
Mar 26, 2026
Merged

feat (provider/gateway): add spend reporting support#13841
shaper merged 2 commits intomainfrom
03-25-feat_provider_gateway_add_spend_reporting_support

Conversation

@shaper
Copy link
Copy Markdown
Collaborator

@shaper shaper commented Mar 26, 2026

Background

The AI Gateway provider needed programmatic access to spend reporting data to enable developers to query usage metrics, costs, and token consumption for their AI applications.

Summary

Added spend reporting support to the AI Gateway provider with a new getSpendReport() method that allows querying cost, token, and request count data aggregated by various dimensions like model, user, tag, provider, or credential type.

Key changes:

  • Added GatewaySpendReport class to handle API requests to the /v1/report endpoint
  • Implemented getSpendReport() method on the gateway provider with support for filtering by date range, user, model, tags, and other parameters
  • Added comprehensive test coverage for the spend reporting functionality
  • Updated documentation with usage examples and parameter descriptions
  • Created example scripts demonstrating how to query spend data and use tags for cost tracking

Manual Verification

Tested the spend reporting functionality by:

  • Running the example scripts to verify API calls work correctly
  • Confirming query parameters are properly serialized (snake_case for API, camelCase for TypeScript)
  • Validating error handling for authentication, rate limiting, and server errors
  • Testing various groupBy options (day, model, tag, user, provider, credential_type)
  • Verifying tag-based filtering works with the existing tagging system

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Copy link
Copy Markdown
Collaborator Author

shaper commented Mar 26, 2026

@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request provider/gateway Issues related to the @ai-sdk/gateway provider labels Mar 26, 2026
@shaper shaper marked this pull request as ready for review March 26, 2026 06:28
@shaper shaper force-pushed the 03-25-feat_provider_gateway_add_spend_reporting_support branch from d574905 to f01df16 Compare March 26, 2026 22:32
@shaper shaper merged commit d30466c into main Mar 26, 2026
18 checks passed
@shaper shaper deleted the 03-25-feat_provider_gateway_add_spend_reporting_support branch March 26, 2026 22:37
@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 26, 2026
vercel-ai-sdk bot pushed a commit that referenced this pull request Mar 26, 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 26, 2026
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 26, 2026

⚠️ Backport to release-v6.0 created but has conflicts: #13859

shaper added a commit that referenced this pull request Mar 26, 2026
This is an automated backport of #13841 to the release-v6.0 branch. FYI
@shaper
This backport has conflicts that need to be resolved manually.

### `git cherry-pick` output

```
Auto-merging content/providers/01-ai-sdk-providers/00-ai-gateway.mdx
CONFLICT (content): Merge conflict in content/providers/01-ai-sdk-providers/00-ai-gateway.mdx
Auto-merging packages/gateway/src/gateway-provider.ts
error: could not apply d30466c... feat (provider/gateway): add spend reporting support (#13841)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
```

---------

Co-authored-by: Walter Korman <shaper@vercel.com>
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk bot commented Mar 26, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.44
@ai-sdk/angular 3.0.0-beta.44
@ai-sdk/gateway 4.0.0-beta.24
@ai-sdk/langchain 3.0.0-beta.44
@ai-sdk/llamaindex 3.0.0-beta.44
@ai-sdk/react 4.0.0-beta.44
@ai-sdk/rsc 3.0.0-beta.45
@ai-sdk/svelte 5.0.0-beta.44
@ai-sdk/vue 4.0.0-beta.44

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 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.

4 participants