On this page
  1. Install
  2. Install and compose
  3. Core configuration
  4. Provider and policy bridges
  5. Metering, telemetry, and caching
  6. Persistence and boundary
  7. API entry points and requirements
  8. Peer dependencies

@playstack/ai

Tenant-aware keys, preflight, metering, telemetry, and cache context around the Vercel AI SDK.

Free. MIT licensed. Check preview availability before installing. See package access.

@playstack/ai supplies tenant-aware keys, entitlement and rate-limit preflight, idempotent usage metering, safe telemetry, and deterministic cache context around native Vercel AI SDK calls.

Install

After confirming preview access, install the package at your application's shared Playstack version:

sh
npm install --save-exact @playstack/ai@0.1.0-beta.1

Check the peer requirements below before choosing a runtime or provider.

Install and compose

ts
import { createAi } from '@playstack/ai'
import { streamText } from 'ai'

const ai = createAi({
  persistence,
  events,
  connections,
  rateLimiter,
  entitlements,
  connectionScope: 'account',
  allowPlatformFallback: false,
  providers: [{
    id: 'anthropic',
    createModel: (modelId, { apiKey }) => anthropic(modelId, { apiKey }),
  }],
  prices: {
    'anthropic:claude-sonnet-4-6': {
      inputMicrosPerMillionTokens: configuredInputPrice,
      outputMicrosPerMillionTokens: configuredOutputPrice,
      currency: 'USD',
    },
  },
  clock,
  ids,
})

const call = await ai.beginCall('anthropic:claude-sonnet-4-6', { accountId, actorId })
const result = await streamText({ model: call.model, prompt })
await ai.completeCall(call, {
  promptTokens: result.usage.inputTokens,
  completionTokens: result.usage.outputTokens,
})

call.model is the provider’s exact model object. Streaming, tools, structured output, and UI hooks remain native SDK APIs.

Core configuration

AiOptions propertyRequiredPurpose
persistenceYesTransactional idempotent usage records and summaries.
eventsYesEmits billable ai.call.completed inside the usage transaction.
connectionsYesLists scoped BYO connections and decrypts selected access tokens.
rateLimiterYesConsumes fail-closed ai.generate account and user buckets.
entitlementsYesAuthorizes provider/model and may supply rate-limit overrides.
providersYesProvider ID, native model factory, and optional platform key resolver.
pricesYesModel-ref input/output micros per million tokens and currency.
connectionScopeYesuser, accountMember, or account.
allowPlatformFallbackNoEnables platform keys only when a provider supplies one.
telemetry, errorReporter, scrubberNoApplication-owned operational bridges.
recordContentNoIncludes scrubbed prompt/completion telemetry; defaults false.
cacheNoExplicit { enabled, hasher }; disabled when absent.
clock, idsYesCall timing and identifiers.

Provider and policy bridges

ContractResponsibility
AiProvidercreateModel(modelId, { apiKey }) and optional platformApiKey().
AiConnectionsScoped list plus decrypted accessToken(connectionId).
AiEntitlementsAuthorize account/actor/provider/model and return optional bucket overrides.
AiRateLimiterConsume ai.generate with both account and user subjects.
AiUsagePersistenceTransactional record with created/duplicate result and account/time summary.
AiTelemetryIsolated started/completed/failed observations.
AiErrorReporterReceives scrubbed failure reports.
AiCacheHasherSHA-256 digest for normalized deterministic inputs.

A present but unusable BYO connection never falls back. Platform fallback requires both the global opt-in and a provider resolver. Bypassed/open rate-limit decisions are rejected so inference stays fail-closed.

Metering, telemetry, and caching

completeCall records by callId; a duplicate with identical usage is safe, while conflicting billable usage fails. Provider prices are captured into the receipt and event so billing consumers do not own the price table.

Prompt/completion recording is off by default. When enabled, content is scrubbed before telemetry and credentials never enter receipts, errors, events, or traces. cacheKey() returns a key only when caching is enabled and temperature is zero; storage remains an application-selected concern.

Persistence and boundary

@playstack/ai/prisma supplies structural PostgreSQL persistence and a managed, non-ejectable schema fragment. Applications own clients and migrations. The package does not wrap the AI SDK, store cache results, load keys, define subscription plans, or hide provider-native behavior.

API entry points and requirements

Reference snapshot: @playstack/ai@0.1.0-beta.1. Import only the entry point your runtime needs. Paths below are relative to the installed package; use Go to Definition in your editor to inspect exact parameters, return types and overloads. Do not import the declaration-file paths directly.

Public entry pointDeclaration file
@playstack/ai./dist/index.d.ts
@playstack/ai/errors./dist/errors.d.ts
@playstack/ai/prisma./dist/prisma.d.ts
@playstack/ai/testing./dist/testing.d.ts
@playstack/ai/playstack.artifacts.jsonNo TypeScript declaration (asset or metadata export).
@playstack/ai/package.jsonNo TypeScript declaration (asset or metadata export).

Node.js engine requirement: >=20. This is not a claim that every entry point works in browsers or Workers.

Peer dependencies

Keep existing framework versions that satisfy these ranges. Install optional peers only when using the corresponding adapter. The package manager resolves ordinary dependencies separately.

PeerCompatible rangeWhen needed
@playstack/connections0.1.0-beta.1Required by the package.
@playstack/rate-limit0.1.0-beta.1Required by the package.

For a complete first program, start with Getting started. For API lookup and partial-example conventions, see Reading the reference. Provider failures, lifecycle requirements and application responsibilities remain described in the guide above; types alone do not establish production safety.

Go

Playstack Pro tag
OriginsPricingBlogNewsletterChangelogStatusRoadmap
ContributorsCommunityIn Use ShowcaseCase StudiesPartnersSponsors
FAQsSupportContact

© 2026 Playstack. All rights reserved.

With OSS
Terms of ServicePrivacy PolicyCookie PolicyImprint

By

Commune Software