@remcostoeten/ai-sdk
v0.2.0
Published
Vercel AI SDK adapter and typed provider factories for the @remcostoeten/ai-core completion seam.
Readme
@remcostoeten/ai-core
owns the contracts and the run lifecycle. This package owns what it takes to
reach a real provider, and its whole job is that the vendor library stays an
implementation detail: no LanguageModel, UIMessage, TextStreamPart or
APICallError appears in anything it exports. Vendor packages are optional
peer dependencies, so you install only the one you use.
- Named factories only:
createGroqProvider,createGeminiProvider,createAnthropicProvider,createOpenAiCompatibleProvider. There is nofromLanguageModel(unknown)escape hatch - Ordering is a guarantee. The model authority is consulted, then the credential resolves, then a socket opens, so an unauthorized model or an unconfigured provider terminalizes with nothing sent
maxRetries: 0, always. A 429 is attempted exactly once, because a hidden retry spends budget and time the caller allotted to one attempt- No provider response body crosses the boundary. Bodies echo prompts and, from some vendors, a key prefix; only a bounded, status-derived sentence reaches the caller
- Credentials arrive through a
CredentialSourceport and model permission through aModelAuthorityport, both yours to implement - Nothing here reads
process.envorDeno.env, so the package makes no assumption about which runtime it is in
Each of those is asserted by a test, including the one that greps the sources
for environment access and the one that asserts the fixture fetch was never
called on a refusal.
The adapter is documented in typescript-core.md, worked usage is in examples.md, and the reasoning behind the boundary is ADR 0003.
Install
Install this package, ai-core, and the vendor package for the provider you
reach.
npm install @remcostoeten/ai-sdk @remcostoeten/ai-core @ai-sdk/groqThe optional peers are @ai-sdk/groq, @ai-sdk/google, @ai-sdk/anthropic
and @ai-sdk/openai-compatible.
Use
import { buildRequest, consumeEvents, createRuntime } from '@remcostoeten/ai-core'
import { createGroqProvider, staticCredential } from '@remcostoeten/ai-sdk'
const provider = await createGroqProvider({
credentials: staticCredential(process.env.GROQ_API_KEY ?? ''),
models: { permits: (_, modelId) => modelId === 'llama-3.3-70b-versatile' },
})
const runtime = createRuntime({ providers: [provider] })From there the run is @remcostoeten/ai-core: build a request, stream it, and
consume the events.
Not implemented
No retries and no key rotation. No fallback or routing between providers. No
structured output. No model listing or capability discovery. Every adapter test
runs against a fixture fetch, so nothing here has been confirmed against a
live endpoint.
xxx, Remco Stoeten MIT
