@spekoai/ai-sdk-provider
v0.1.0
Published
Speko provider for the Vercel AI SDK - routed speech and transcription across every voice provider
Readme
@spekoai/ai-sdk-provider
Speko provider for the Vercel AI SDK - routed speech and transcription across every voice provider.
Speko is an OpenRouter-style routing layer for the voice stack (TTS + STT). One API key, one provider entry in your AI SDK code, and Speko's benchmark-driven router picks the best upstream provider (ElevenLabs, Cartesia, Deepgram, AssemblyAI, OpenAI, and more) per request - and fails over automatically when a provider degrades.
Implements the AI SDK provider specification v4 (SpeechModelV4 +
TranscriptionModelV4), for ai v7.
Install
npm install @spekoai/ai-sdk-provider aiSetup
Get an API key at platform.speko.dev
and set it as SPEKO_API_KEY, or pass it explicitly:
import { createSpeko } from '@spekoai/ai-sdk-provider';
const speko = createSpeko({
apiKey: process.env.SPEKO_API_KEY,
// baseURL: 'https://api.speko.dev',
});The default instance reads SPEKO_API_KEY from the environment:
import { speko } from '@spekoai/ai-sdk-provider';Speech
import { speko } from '@spekoai/ai-sdk-provider';
import { generateSpeech } from 'ai';
const { audio } = await generateSpeech({
model: speko.speech('auto'),
text: 'Welcome to Speko.',
voice: 'QtY3JBOUKEB5xzrRfOKc', // optional, provider-specific
providerOptions: {
speko: { language: 'en', optimizeFor: 'latency' },
},
});
// audio.uint8Array - WAV bytes (Speko synthesizes raw PCM; this provider
// wraps it into a WAV container at the routed provider's sample rate).Pass outputFormat: 'pcm' to receive the raw s16le mono PCM instead of WAV.
The sample rate is reported in providerMetadata.speko.sampleRate.
Transcription
import { speko } from '@spekoai/ai-sdk-provider';
import { transcribe } from 'ai';
import { readFile } from 'node:fs/promises';
const result = await transcribe({
model: speko.transcription('auto'),
audio: await readFile('call.wav'),
providerOptions: {
speko: {
language: 'es-MX',
keywords: ['Speko', 'Vercel'],
},
},
});
console.log(result.text);
console.log(result.providerMetadata.speko);
// { provider: 'deepgram', model: 'nova-3', confidence: 0.93, failoverCount: 0, scoresRunId: '...' }Model ids
The model id selects a routing strategy, not a single model:
| Model id | Behavior |
| --- | --- |
| auto | Router default for your organization's routing policy |
| auto-fast | Bias toward latency |
| auto-quality | Bias toward accuracy/quality |
| auto-cheap | Bias toward cost |
| deepgram | Pin routing and failover to one upstream provider |
| elevenlabs/eleven_multilingual_v2 | Pin the provider and request a specific upstream model |
speko.transcription('auto-quality');
speko.speech('elevenlabs/eleven_multilingual_v2');Routing options (providerOptions.speko)
This is where Speko differs from single-vendor providers: the options control the router, not one model.
| Option | Applies to | Description |
| --- | --- | --- |
| language | both | BCP-47 language tag, e.g. en, es-MX. Routing is language-aware. Defaults to en |
| region | both | Region to rank providers in, e.g. us-east4, eu-west1 |
| optimizeFor | both | balanced | accuracy | latency | cost; overrides the model id preset |
| providers | both | Restrict routing AND failover to these upstream providers |
| keywords | transcription | Domain keywords forwarded to the routed STT provider |
| model | speech | Upstream model override, e.g. sonic-2 |
| spokenForm | speech | Deterministic spoken-form normalization before synthesis |
Failover
Failover is handled server-side by Speko: if the routed provider errors or
degrades, the request is retried against the next-ranked provider before
the call returns. The number of failovers taken is reported in
providerMetadata.speko.failoverCount. Use providers to control the pool
the router (and its failover) may use.
Notes
- The one-shot transcription endpoint does not report per-word timing yet:
when the input duration is deterministic (WAV or raw PCM input) the
provider reports
durationInSecondsand a single whole-transcript segment; otherwisesegmentsis empty anddurationInSecondsis undefined. languageModel,embeddingModel, andimageModelthrowNoSuchModelError- Speko is a voice platform.
Links
- Speko documentation
- Dashboard and API keys
- TypeScript SDK (
@spekoai/sdk)
License
MIT
