Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Elevenlabs Elevenlabs python RawBaseClient

From Leeroopedia
Field Value
sources src/elevenlabs/raw_base_client.py
domains Raw HTTP Client, Conversational AI Agent Branches, Voice Preview, Low-Level API Access
last_updated 2026-02-15

Overview

The RawBaseClient module provides low-level HTTP wrapper classes that expose raw HTTP responses from the ElevenLabs API. Unlike the higher-level SDK clients that parse responses into typed models, these classes return HttpResponse / AsyncHttpResponse objects that include the full HTTP response metadata (status code, headers) alongside the response data.

This file was auto-generated by Fern from the ElevenLabs API definition and contains two classes:

  • RawBaseElevenLabs - Synchronous raw HTTP client
  • AsyncRawBaseElevenLabs - Asynchronous raw HTTP client

Each class provides two methods:

  • delete_v_1_convai_agents_agent_id_branches_branch_id - Deletes a conversational AI agent branch by agent ID and branch ID.
  • save_a_voice_preview - Adds a generated voice preview to the voice library.

Typical usage:

These raw clients are used internally by the SDK when consumers need direct access to HTTP response metadata. They are not typically instantiated directly by end users.

Code Reference

Source file: src/elevenlabs/raw_base_client.py

RawBaseElevenLabs (Synchronous)

class RawBaseElevenLabs:
    def __init__(self, *, client_wrapper: SyncClientWrapper): ...

    def delete_v_1_convai_agents_agent_id_branches_branch_id(
        self, agent_id: str, branch_id: str,
        *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]: ...

    def save_a_voice_preview(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[None]: ...

AsyncRawBaseElevenLabs (Asynchronous)

class AsyncRawBaseElevenLabs:
    def __init__(self, *, client_wrapper: AsyncClientWrapper): ...

    async def delete_v_1_convai_agents_agent_id_branches_branch_id(
        self, agent_id: str, branch_id: str,
        *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]: ...

    async def save_a_voice_preview(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]: ...

Import statement:

from elevenlabs.raw_base_client import RawBaseElevenLabs, AsyncRawBaseElevenLabs

Dependencies

Module Usage
elevenlabs.core.api_error.ApiError Raised on non-2xx HTTP responses
elevenlabs.core.client_wrapper.SyncClientWrapper Synchronous HTTP client wrapper (wraps httpx)
elevenlabs.core.client_wrapper.AsyncClientWrapper Asynchronous HTTP client wrapper (wraps httpx)
elevenlabs.core.http_response.HttpResponse Typed synchronous HTTP response container
elevenlabs.core.http_response.AsyncHttpResponse Typed asynchronous HTTP response container
elevenlabs.core.jsonable_encoder.jsonable_encoder URL path parameter encoding
elevenlabs.core.request_options.RequestOptions Per-request configuration (timeouts, headers, etc.)

I/O Contract

delete_v_1_convai_agents_agent_id_branches_branch_id

Deletes a specific branch of a conversational AI agent.

API Endpoint: DELETE /v1/convai/agents/{agent_id}/branches/{branch_id}

Input Parameters:

Parameter Type Required Description
agent_id str Yes The unique identifier of the conversational AI agent
branch_id str Yes The unique identifier of the branch to delete
request_options Optional[RequestOptions] No Request-specific configuration (timeouts, custom headers, etc.)

Return Value:

Type Description
HttpResponse[None] / AsyncHttpResponse[None] Raw HTTP response with data=None on success (2xx status)

Raises:

Exception Condition
ApiError Non-2xx HTTP status code. Contains status_code, headers, and body (JSON or text).

save_a_voice_preview

Adds a generated voice to the voice library.

API Endpoint: POST /v1/text-to-voice/create-voice-from-preview

Input Parameters:

Parameter Type Required Description
request_options Optional[RequestOptions] No Request-specific configuration (timeouts, custom headers, etc.)

Return Value:

Type Description
HttpResponse[None] / AsyncHttpResponse[None] Raw HTTP response with data=None on success (2xx status)

Raises:

Exception Condition
ApiError Non-2xx HTTP status code. Contains status_code, headers, and body (JSON or text).

Error Handling Pattern

Both methods follow the same error handling pattern:

try:
    if 200 <= _response.status_code < 300:
        return HttpResponse(response=_response, data=None)
    _response_json = _response.json()
except JSONDecodeError:
    raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

This ensures that:

  • 2xx responses return an HttpResponse with data=None.
  • Non-2xx responses with JSON body raise ApiError with the parsed JSON as the body.
  • Non-2xx responses without JSON body raise ApiError with the raw text as the body.

Usage Examples

Deleting an Agent Branch (Synchronous)

from elevenlabs.core.client_wrapper import SyncClientWrapper
from elevenlabs.raw_base_client import RawBaseElevenLabs
from elevenlabs.core.api_error import ApiError

# Typically accessed through the main client, not instantiated directly
raw_client = RawBaseElevenLabs(client_wrapper=sync_wrapper)

try:
    response = raw_client.delete_v_1_convai_agents_agent_id_branches_branch_id(
        agent_id="agent_abc123",
        branch_id="branch_def456",
    )
    print(f"Status: {response.response.status_code}")  # 200
except ApiError as e:
    print(f"API error {e.status_code}: {e.body}")

Deleting an Agent Branch (Asynchronous)

import asyncio
from elevenlabs.core.client_wrapper import AsyncClientWrapper
from elevenlabs.raw_base_client import AsyncRawBaseElevenLabs
from elevenlabs.core.api_error import ApiError

async def delete_branch():
    raw_client = AsyncRawBaseElevenLabs(client_wrapper=async_wrapper)

    try:
        response = await raw_client.delete_v_1_convai_agents_agent_id_branches_branch_id(
            agent_id="agent_abc123",
            branch_id="branch_def456",
        )
        print(f"Status: {response.response.status_code}")
    except ApiError as e:
        print(f"API error {e.status_code}: {e.body}")

asyncio.run(delete_branch())

Saving a Voice Preview

from elevenlabs.raw_base_client import RawBaseElevenLabs
from elevenlabs.core.api_error import ApiError

raw_client = RawBaseElevenLabs(client_wrapper=sync_wrapper)

try:
    response = raw_client.save_a_voice_preview()
    print(f"Voice preview saved. Status: {response.response.status_code}")
except ApiError as e:
    print(f"Failed to save voice preview: {e.status_code} - {e.body}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment