Prerequisites
Before installing the SDK, ensure you have:- Node.js 20 or higher - The SDK uses modern JavaScript features
- pnpm (recommended) or npm/yarn - Package manager of your choice
- OpenAI API key - Required for LLM, transcription, and speech models
While this SDK is optimized for OpenAI models, it works with any AI SDK compatible provider through the Vercel AI SDK.
Install the Package
Installvoice-agent-ai-sdk and its peer dependencies:
Package Details
voice-agent-ai-sdk- The core SDK (version 1.0.1+)ai- Vercel AI SDK (peer dependency, version 6.0.0+)@ai-sdk/openai- OpenAI provider for AI SDK
The SDK also includes TypeScript definitions out of the box - no need to install separate
@types packages.Environment Setup
Create a.env file in your project root to store API keys and configuration:
.env
Loading Environment Variables
Load environment variables at the start of your application:dotenv explicitly:
Get Your OpenAI API Key
If you don’t have an OpenAI API key yet:- Go to platform.openai.com
- Sign in or create an account
- Navigate to API Keys in your account settings
- Click Create new secret key
- Copy the key and add it to your
.envfile
Make sure you have credits in your OpenAI account. The SDK uses:
- Chat models (e.g.,
gpt-4o) for text generation whisper-1for audio transcription- Speech models (e.g.,
gpt-4o-mini-tts) for text-to-speech
Additional Dependencies (Optional)
Depending on your use case, you may need:For Tool Calling
For WebSocket Server
Verify Installation
Create a simple test file to verify everything is set up correctly:test.ts
Next Steps
Quickstart Guide
Build your first voice agent with streaming text and speech