Skip to content

Feat/ai sdk wrapper#50

Merged
thedevyashsaini merged 11 commits into
mainfrom
feat/ai-sdk-wrapper
May 28, 2026
Merged

Feat/ai sdk wrapper#50
thedevyashsaini merged 11 commits into
mainfrom
feat/ai-sdk-wrapper

Conversation

@thedevyashsaini

Copy link
Copy Markdown
Member

No description provided.

- biller.ai(sdk, opts) returns proxied AI SDK with per-step billing
- Auto-injects onStepFinish for streamText, generateText, streamObject, generateObject
- Chains user's own callbacks alongside billing (non-blocking)
- biller.trackAI() for manual tracking at onStepFinish/onFinish
- Supports cached input/output token billing with separate debit config
- Per-call overrides for inputDebit/outputDebit/cacheDebit
- Zero any types, fully generic over TTags
…ad logic

- wrap.ts billingStep now delegates to biller.trackAI()
- Removes duplicate buildAIPayload + aiTokenStreamConsumer calls
- trackAI is the single canonical billing entry point
- Level 1: biller.ai(ai, {inputDebit, outputDebit}) auto-wrapper
- Level 1b: user's own onStepFinish chained with billing
- Level 2: Manual biller.trackAI() in onStepFinish callback
- Demonstrates both streamText and generateText patterns
- Return Record<string, (params) => Promise<unknown>> instead of Record<string, unknown>
- Example now works cleanly without any as casts
- biller.ai() now infers TSDK from the input module via const generic
- Returns TSDK & overlay — original types (including return) survive
- streamText still returns StreamTextResult, generateText returns GenerateTextResult
- Example now has zero casts: no as WrappedFn, no as string, no as unknown
- Removed unnecessary BillableAI/StreamTextResult/GenerateTextResult types
- Omit streamText/generateText/streamObject/generateObject from TSDK
- Re-add them with Record<string, unknown> params accepting userId
- Return types preserved: streamText returns {text: Promise<string>}, generateText returns {text: string}
…ct AI SDK types

- WithUserId<TSDK> type: Omit wrapped fns, re-add with P & BillableCallParams
- Preserves original AI SDK param types (model, prompt, tools, etc.)
- Preserves original return types (StreamTextResult, GenerateTextResult)
- User gets full AI SDK intellisense + userId
Signed-off-by: Devyash Saini <dysaini2004@gmail.com>
… clean up types

- Fix cacheTokens operator precedence (?? vs !==) — input/outputCacheTokens
  now correctly assigned from usage, not from overrides
- Remove onFinish double-billing — per-step via onStepFinish covers usage fully
- Remove dead StripScrawnParams type
- Make BillableCallParams.userId optional — no wasted '' default
…cation

1. Remove unused TagName type from pricing/types.ts
2. Add formatValidationError helper — removes duplicate Zod issue formatting (3 sites)
3. Add performAIStreamCall helper — removes duplicate gRPC stream call (2 sites)
4. Extract initClient/buildCallOptions into grpc/utils.ts — shared by both builders
5. Replace duplicate client init in requestBuilder + streamRequestBuilder with shared utils
6. Extract isValidPriceExpr helper — deduplicates null/type/kind check in both schemas
@thedevyashsaini thedevyashsaini merged commit 38dc252 into main May 28, 2026
2 of 3 checks passed
@thedevyashsaini thedevyashsaini deleted the feat/ai-sdk-wrapper branch May 28, 2026 05:52
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.

1 participant