Skip to content

Add AI SDK Provider#167

Merged
selander-stripe merged 17 commits intomainfrom
add-ai-sdk-provider
Oct 31, 2025
Merged

Add AI SDK Provider#167
selander-stripe merged 17 commits intomainfrom
add-ai-sdk-provider

Conversation

@selander-stripe
Copy link
Copy Markdown
Collaborator

@selander-stripe selander-stripe commented Oct 27, 2025

Add Stripe AI SDK packages for Vercel AI SDK integration

This PR adds three new packages under llm/ for integrating Stripe billing with AI applications.

Packages Added

@stripe/ai-sdk/provider

A custom Vercel AI SDK provider that routes requests through Stripe's llm.stripe.com proxy for automatic usage tracking and billing. Provides a unified interface to OpenAI, Google Gemini, and Anthropic Claude models.

import { createStripe } from '@stripe/ai-sdk/provider';
import { generateText } from 'ai';

const stripe = createStripe({
  apiKey: process.env.STRIPE_API_KEY,
  customerId: 'cus_xxxxx',
});

const result = await generateText({
  model: stripe('openai/gpt-5'),
  prompt: 'Hello world',
});

@stripe/ai-sdk/meter

A wrapper that adds Stripe billing tracking to any AI SDK v2 language model. Allows developers to continue using their existing provider setup while gaining billing capabilities.

import { meteredModel } from '@stripe/ai-sdk/meter';
import { openai } from '@ai-sdk/openai';

const model = meteredModel(
  openai('gpt-4o-mini'),
  process.env.STRIPE_API_KEY,
  'cus_xxxxx'
);

@stripe/token-billing

A generic token metering library for native AI SDKs (OpenAI, Anthropic, Google Gemini) without framework dependencies. Automatically detects provider types and tracks token usage for billing.

import OpenAI from 'openai';
import { createTokenMeter } from '@stripe/token-billing';

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const meter = createTokenMeter(process.env.STRIPE_API_KEY);

const response = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Hello!' }],
});

meter.trackUsage(response, 'cus_xxxxx');

Notes

  • All packages support streaming, non-streaming responses, and automatic token tracking
  • The AI SDK provider currently does not support tool calling, text embeddings, or image generation (graceful error handling included)
  • Comprehensive test coverage and documentation included
  • Requires access to Stripe's Billing for LLM Tokens Private Preview

Copy link
Copy Markdown
Collaborator

@matv-stripe matv-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick skim 1

Copy link
Copy Markdown

@nm-stripe nm-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@selander-stripe selander-stripe marked this pull request as ready for review October 30, 2025 15:02
selander-stripe and others added 3 commits October 30, 2025 12:19
Co-authored-by: Steve Kaliski <59668283+stevekaliski-stripe@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@mpbagwell-stripe mpbagwell-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mix of widely applicable suggestions!

Co-authored-by: matv-stripe <55463370+matv-stripe@users.noreply.github.com>
selander-stripe and others added 4 commits October 30, 2025 16:00
Co-authored-by: matv-stripe <55463370+matv-stripe@users.noreply.github.com>
Co-authored-by: mpbagwell-stripe <mpbagwell@stripe.com>
Co-authored-by: mpbagwell-stripe <mpbagwell@stripe.com>

### `@stripe/token-meter`

@stripe/token-meter provides generic token metering for native AI SDKs with automatic Stripe billing integration. Unlike the ai-sdk package, this works directly with native SDKs from OpenAI, Anthropic, and Google Gemini without requiring the Vercel AI SDK or any other framework.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token-billing or token-meter/

@selander-stripe selander-stripe merged commit 40df32b into main Oct 31, 2025
8 checks passed
@selander-stripe selander-stripe deleted the add-ai-sdk-provider branch October 31, 2025 14:49
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.

6 participants