@elevenlabs/types

中文文档
0.29.0发布于 2026/11/05MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 609.1万

AsyncAPI contracts and generated TypeScript types for ElevenLabs agent communication

原始使用文档
文档目录10 节
  1. Overview
  2. Usage
  3. Basic Import
  4. Direct Type Imports
  5. Type Categories
  6. Development
  7. Generating Types
  8. Project Structure
  9. Adding New Types
  10. Adding New API Schemas

@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 agent
      • AudioAlignmentEvent - Character-level timing data embedded in audio events for text-to-speech synchronization
      • AgentResponseClientEvent - Text responses from the agent
      • UserTranscriptionClientEvent - Transcriptions of user speech
      • InterruptionEvent - Interruption notifications
    • Scribe API:
      • SessionStartedMessage - Transcription session started
      • PartialTranscriptMessage - Interim transcription results
      • CommittedTranscriptMessage - Committed transcription results
      • CommittedTranscriptWithTimestampsMessage - Committed results with word timestamps
      • ScribeErrorMessage - Error events
      • ScribeAuthErrorMessage - Authentication errors
  • Outgoing - Messages sent to the ElevenLabs server

    • Agent API:
      • UserMessage - Text messages from the user
      • UserFeedback - User feedback (like/dislike)
      • ConversationInitiation - Session initialization
      • ClientToolResult - Results from client-side tool execution
    • Scribe API:
      • InputAudioChunk - Audio data for transcription

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-types

Project 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 exports

Adding New Types

  1. Update the AsyncAPI specification in the appropriate file (e.g., schemas/agent.asyncapi.yaml or schemas/scribe.asyncapi.yaml)
  2. Run pnpm generate to regenerate TypeScript types from all schemas
  3. The types will automatically be available in the appropriate namespace

Adding New API Schemas

  1. Create a new AsyncAPI specification in schemas/ with the naming pattern *.asyncapi.yaml
  2. Run pnpm generate - the script will automatically discover and process all schema files
  3. The generated types will be merged into the existing type exports

版本与发布记录

@elevenlabs/types 共发布 40 个版本,首次发布于 2025/09/26;过去 12 个月发布了 35 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.29.0latest2026/11/058 天前
0.28.02026/11/049 天前
0.27.02026/11/0211 天前
0.26.02026/10/2618 天前
0.25.02026/10/1430 天前
0.24.02026/09/291 个月前

其他发布通道:next → 0.7.0-rc.0。

关于 @elevenlabs/types 的常见问题

@elevenlabs/types 是什么?

AsyncAPI contracts and generated TypeScript types for ElevenLabs agent communication

如何安装 @elevenlabs/types?

在项目目录运行 npm install @elevenlabs/types,或使用 pnpm add / yarn add / bun add。

@elevenlabs/types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elevenlabs/types 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@elevenlabs/types 可以商用吗?

@elevenlabs/types 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@elevenlabs/types 的下载量有多少?

根据 npm 官方下载统计,@elevenlabs/types 在 2026/10/14 – 2026/11/12 这 30 天内被下载 6,091,085 次,日均约 203,036 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elevenlabs/types 还在维护吗?

最新版本 0.29.0 发布于 2026/11/05(8 天前);至今共发布 40 个版本,其中过去 12 个月发布了 35 个;首次发布于 2025/09/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。