@elevenlabs/types
v0.4.0
Published
AsyncAPI contracts and generated TypeScript types for ElevenLabs agent communication
Keywords
Readme
@elevenlabs/types
TypeScript type definitions for ElevenLabs APIs, auto-generated from AsyncAPI specifications.
Overview
This package provides strongly-typed interfaces for all messages exchanged between ElevenLabs clients and various APIs (Agents, Scribe). Types are automatically generated from AsyncAPI specifications to ensure they stay in sync with the API contracts.
Usage
Basic Import
import { Incoming, Outgoing } from "@elevenlabs/types";
// Handle incoming messages from the server
const handleAudio = (message: Incoming.AudioClientEvent) => {
console.log("Received audio:", message.audioEvent.audioBase_64);
};
// Send outgoing messages to the server
const userMessage: Outgoing.UserMessage = {
reservedType: "user_message",
reservedText: "Hello, agent!",
};Direct Type Imports
// Import specific types directly
import {
Audio,
UserTranscript,
AgentResponse,
ConversationInitiation,
} from "@elevenlabs/types";
// Use types in your application
const audio: Audio = {
reservedType: "audio",
audioEvent: {
audioBase_64: "base64_encoded_audio",
eventId: 123,
},
};Type Categories
The types are organized into two main categories:
Incoming- Messages received from the ElevenLabs server- Agent API:
AudioClientEvent- Audio data from the agentAgentResponseClientEvent- Text responses from the agentUserTranscriptionClientEvent- Transcriptions of user speechInterruptionEvent- Interruption notifications
- Scribe API:
SessionStartedMessage- Transcription session startedPartialTranscriptMessage- Interim transcription resultsCommittedTranscriptMessage- Committed transcription resultsCommittedTranscriptWithTimestampsMessage- Committed results with word timestampsScribeErrorMessage- Error eventsScribeAuthErrorMessage- Authentication errors
- Agent API:
Outgoing- Messages sent to the ElevenLabs server- Agent API:
UserMessage- Text messages from the userUserFeedback- User feedback (like/dislike)ConversationInitiation- Session initializationClientToolResult- Results from client-side tool execution
- Scribe API:
InputAudioChunk- Audio data for transcription
- Agent API:
Development
Generating Types
Types are automatically generated from the AsyncAPI specification:
# Generate types from AsyncAPI spec
pnpm generate
# Build the package
pnpm build
# Type check without building
pnpm check-typesProject Structure
packages/types/
├── schemas/
│ ├── agent.asyncapi.yaml # Agent API AsyncAPI specification
│ └── scribe.asyncapi.yaml # Scribe API AsyncAPI specification
├── scripts/
│ └── generate-all-types.ts # Generation script (processes all schemas)
├── generated/
│ └── types/
│ ├── asyncapi-types.ts # All generated types
│ ├── incoming.ts # Barrel export for incoming messages
│ └── outgoing.ts # Barrel export for outgoing messages
└── src/
└── index.ts # Main entry point with organized exportsAdding New Types
- Update the AsyncAPI specification in the appropriate file (e.g.,
schemas/agent.asyncapi.yamlorschemas/scribe.asyncapi.yaml) - Run
pnpm generateto regenerate TypeScript types from all schemas - The types will automatically be available in the appropriate namespace
Adding New API Schemas
- Create a new AsyncAPI specification in
schemas/with the naming pattern*.asyncapi.yaml - Run
pnpm generate- the script will automatically discover and process all schema files - The generated types will be merged into the existing type exports
