ElevenLabs.Net 1.1.0

dotnet add package ElevenLabs.Net --version 1.1.0
                    
NuGet\Install-Package ElevenLabs.Net -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ElevenLabs.Net" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ElevenLabs.Net" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ElevenLabs.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ElevenLabs.Net --version 1.1.0
                    
#r "nuget: ElevenLabs.Net, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ElevenLabs.Net@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ElevenLabs.Net&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ElevenLabs.Net&version=1.1.0
                    
Install as a Cake Tool

ElevenLabs C# Library

LOGO

fern shield Discord Twitter nuget shield

The official C# SDK for ElevenLabs. ElevenLabs brings the most compelling, rich and lifelike voices to creators and developers in just a few lines of code.

📖 API & Docs

Check out the HTTP API documentation. A full reference for this library is available here.

Install

dotnet add package ElevenLabs.Net

Usage

Main Models

  1. Eleven v4 (eleven_v4)

    • Highest quality and most expressive speech, with reliable voice cloning across long generations
    • 90+ languages with consistent voice quality across language switches
    • Up to 10,000 characters (~10 minutes of audio) per request
    • Used via the Text to Dialogue API
  2. Eleven v4 Turbo (eleven_v4_turbo)

    • State-of-the-art real-time speech, with a median latency of ~100ms
    • 90+ languages
    • Ideal for voice agents and other latency-sensitive use cases
  3. Eleven Multilingual v2 (eleven_multilingual_v2)

    • Excels in stability, language diversity, and accent accuracy
    • The most stable choice for long-form Text to Speech
    • Supports 29 languages
  4. Eleven Flash v2.5 (eleven_flash_v2_5)

    • Ultra-low latency and lowest cost
    • Supports 32 languages

For more detailed information about these models and others, visit the ElevenLabs Models documentation.

Instantiate and use the client with the following:

using ElevenLabs;

// Reads the API key from the ELEVENLABS_API_KEY environment variable.
// Pass it explicitly with new ElevenLabsClient("YOUR_API_KEY") if you prefer.
var client = new ElevenLabsClient();

await using var audio = await client.TextToSpeech.ConvertAsync(
    "JBFqnCBsd6RMkjVDRZzb",
    new ConvertTextToSpeechRequest
    {
        OutputFormat = ConvertTextToSpeechRequestOutputFormat.Mp344100128,
        Body = new BodyTextToSpeechFull
        {
            Text = "The first move is what sets everything in motion.",
            ModelId = "eleven_multilingual_v2",
        },
    }
);

// The response is an audio stream; copy it to a file.
await using var file = File.Create("output.mp3");
await audio.CopyToAsync(file);

Text to Dialogue (Eleven v4)

Eleven v4 and Eleven v4 Turbo are served through the Text to Dialogue API, which turns a list of speaker turns into a single expressive audio stream.

await using var audio = await client.TextToDialogue.ConvertAsync(
    new ConvertTextToDialogueRequest
    {
        OutputFormat = ConvertTextToDialogueRequestOutputFormat.Mp344100128,
        Body = new BodyTextToDialogueMultiVoiceV1TextToDialoguePost
        {
            ModelId = "eleven_v4",
            Inputs = new List<DialogueInput>
            {
                new() { Text = "[giggling] Knock knock", VoiceId = "JBFqnCBsd6RMkjVDRZzb" },
                new() { Text = "[curious] Who is there?", VoiceId = "Aw4FAjKCGjjNkVhN1Xmq" },
            },
        },
    }
);

await using var file = File.Create("dialogue.mp3");
await audio.CopyToAsync(file);

Voices

List all your available voices with SearchAsync.

var response = await client.Voices.SearchAsync(new SearchVoicesRequest());
foreach (var voice in response.Voices)
{
    Console.WriteLine(voice.Name);
}

For information about the structure of the voices output, please refer to the official ElevenLabs API documentation for Get Voices.

Streaming

Stream audio in real-time, as it's being generated. StreamAsync returns the HTTP response body as a Stream, so you can read and play or write each chunk before the server has finished.

await using var audio = await client.TextToSpeech.StreamAsync(
    "JBFqnCBsd6RMkjVDRZzb",
    new StreamTextToSpeechRequest
    {
        OutputFormat = StreamTextToSpeechRequestOutputFormat.Mp344100128,
        Body = new BodyTextToSpeechStream
        {
            Text = "This is a... streaming voice.",
            ModelId = "eleven_multilingual_v2",
        },
    }
);

await using var file = File.Create("output.mp3");
await audio.CopyToAsync(file);

Environments

This SDK allows you to configure different environments for API requests. It defaults to the production environment.

using ElevenLabs;

var client = new ElevenLabsClient(
    clientOptions: new ClientOptions
    {
        BaseUrl = ElevenLabsClientEnvironment.ProductionUs,
    }
);

Available environments:

  • ElevenLabsClientEnvironment.Production
  • ElevenLabsClientEnvironment.ProductionUs
  • ElevenLabsClientEnvironment.ProductionEu
  • ElevenLabsClientEnvironment.ProductionIndia
  • ElevenLabsClientEnvironment.ProductionSingapore

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of ElevenLabsClientApiException is thrown. The HTTP status code is available via StatusCode and the raw response body via Body. Specific status codes throw named subclasses (for example NotFoundError for a 404), so you can catch the one you care about.

using ElevenLabs;

try
{
    var response = await client.TextToSpeech.ConvertAsync(...);
}
catch (NotFoundError)
{
    // Handle a 404 specifically.
}
catch (ElevenLabsClientApiException e)
{
    Console.WriteLine($"API error occurred: {e.Message}");
    Console.WriteLine($"Status code: {e.StatusCode}");
    Console.WriteLine($"Response body: {e.Body}");
}

WebSockets

Real-time channels are created from the client with a Create...Api factory. Subscribe to the channel's receive event, call ConnectAsync, then Send messages (typed, string, or byte[]); CloseAsync or disposal closes the connection.

await using var dubbing = client.CreateDubbingApi(
    new DubbingApi.Options
    {
        TargetLanguage = "es",
        SourceLanguage = "en",
    }
);

dubbing.ReceiveDubbingStreamMessage.Subscribe(message =>
{
    // Handle each message.
});

await dubbing.ConnectAsync();
await dubbing.Send(/* a SendDubbingStreamMessage */);

await dubbing.CloseAsync();

The SDK has one channel per factory:

  • client.CreateDubbingApi(...) returns an IDubbingApi
  • client.CreateTextToSpeechApi(...) returns an ITextToSpeechApi
  • client.CreateTextToSpeechMultiContextApi(...) returns an ITextToSpeechMultiContextApi
  • client.CreateTextToDialogueApi(...) returns an ITextToDialogueApi
  • client.CreateTextToDialogueMultiContextApi(...) returns an ITextToDialogueMultiContextApi
  • client.CreateSpeechToTextApi(...) returns an ISpeechToTextApi
  • client.CreateSpeechEngineApi(...) returns an ISpeechEngineApi
  • client.CreateTranslationApi(...) returns an ITranslationApi

Webhooks

ElevenLabs signs each webhook it sends with your webhook secret. client.Webhooks.ConstructEvent verifies the ElevenLabs-Signature header and returns the decoded event as a JsonObject. Pass the raw request body exactly as received: re-serializing a deserialized body changes the bytes and breaks verification.

using ElevenLabs;

// In an ASP.NET Core minimal API handler:
using var reader = new StreamReader(request.Body);
var rawBody = await reader.ReadToEndAsync();

try
{
    var evt = client.Webhooks.ConstructEvent(
        rawBody,
        request.Headers["ElevenLabs-Signature"].ToString(),
        Environment.GetEnvironmentVariable("ELEVENLABS_WEBHOOK_SECRET")!
    );
    Console.WriteLine(evt["type"]);
}
catch (ElevenLabsClientApiException)
{
    // Missing or invalid signature, or a timestamp older than 30 minutes.
    return Results.BadRequest();
}

ElevenLabs.Webhooks.WebhookVerifier.ConstructEvent does the same without a client.

Composing music with metadata

POST /v1/music/detailed returns the song's metadata and its audio file in one multipart/mixed response. MusicDetailed.ComposeDetailedAsync sends that request and splits the response for you.

using ElevenLabs;
using ElevenLabs.Music;

var client = new ElevenLabsClient();
var music = new MusicDetailed(client);

var song = await music.ComposeDetailedAsync(
    new ComposeDetailedMusicRequest
    {
        Body = new BodyComposeMusicWithADetailedResponseV1MusicDetailedPost
        {
            Prompt = "Epic orchestral music with dramatic strings and powerful brass",
            MusicLengthMs = 60000,
        },
    }
);

Console.WriteLine(song.Json["song_metadata"]?["title"]);
File.WriteAllBytes(song.Filename, song.Audio);
  • Json is the metadata part as the API sends it: composition_plan, song_metadata and words_timestamps.
  • Audio is the audio file's bytes and Filename the name the API suggests for it.
  • SongId is set when the request has StoreForInpainting enabled.
  • Use this rather than client.Music.ComposeDetailedAsync, which can't decode the multipart response.

Flows: wait for a generation

Flows generations and template runs finish asynchronously: CreateAsync returns straight away with a pending status. CreateAndWaitAsync creates the generation, then polls GetAsync until it is completed or failed and returns the final response. It is on client.Flows.Image, client.Flows.Video, client.Flows.TextToSpeech and client.Flows.Templates.Runs.

using ElevenLabs;
using ElevenLabs.Flows;

var client = new ElevenLabsClient();

var generation = await client.Flows.Image.CreateAndWaitAsync(
    new CreateImageRequest
    {
        Body = new ImageGenerationRequest(
            new ImageGenerationRequest.BytedanceSeedream5Lite(
                new BytedanceSeedream5LiteRequest
                {
                    Prompt = "A corgi in a tiny lifeguard chair on a sunlit beach, photorealistic",
                    ModelId = BytedanceSeedream5LiteRequestModelId.BytedanceSeedream5Lite,
                }
            )
        ),
    },
    new FlowsWaitOptions { WaitTimeout = TimeSpan.FromMinutes(5) }
);

if (generation.IsCompleted)
{
    Console.WriteLine(generation.AsCompleted().ContentUrl);
}
else
{
    Console.WriteLine(generation.AsFailed().ErrorMessage);
}
  • A failed generation or run is returned, not thrown. Check the status on the result.
  • Between status checks it waits as long as the server's Retry-After header says, never less than MinPollInterval (3 seconds by default, 0.5 seconds at the least), plus up to 20% jitter.
  • WaitTimeout bounds the whole wait. It defaults to null, which waits indefinitely. When it runs out, FlowsWaitTimeoutException is thrown with the Id (and TemplateId for a run) so you can resume with GetAsync. The work keeps running on the server.
  • RequestOptions apply to the create call and to every status check, except AdditionalBodyProperties, which only the create call gets.

For a template run, pass the template id:

using ElevenLabs.Flows.Templates;

var run = await client.Flows.Templates.Runs.CreateAndWaitAsync(
    "tpl_123",
    new CreateRunsRequest { Body = new TemplateRunCreateRequest() }
);

Waiting holds a process open, so this suits scripts and quickstarts. In production, set Webhook on the request and handle the webhook event instead.

Agent tools as code

ElevenLabs.AgentTools builds agent tools in code: webhook tools, client tools and system tools such as ending or transferring the call. Build() validates the tool and returns the ToolRequestModel that client.Agents.Tools.CreateAsync and UpdateAsync accept. ToJsonString() writes the same format the ElevenLabs CLI keeps in tool_configs/*.json, and Tool.FromJson loads it back for editing.

using ElevenLabs;
using ElevenLabs.Agents;
using ElevenLabs.AgentTools;
using ElevenLabs.AgentWorkflows;
// ElevenLabs.Tool is a generated model, so name the builder explicitly.
using Tool = ElevenLabs.AgentTools.Tool;

var getOrder = Tool.Webhook("get_order", "Look up an order by the number the caller gives")
    .Get("https://api.example.com/orders/{order_id}")
    .PathParam("order_id", Schema.String().Describe("The order number, e.g. A-1042"))
    .QueryParam("include", Schema.String().Constant("items"))
    .Header("Authorization", Header.Secret("sec_orders_api"))
    .Header("X-Caller", Header.Variable("system__caller_id"))
    .Assign("order_status", "order.status")
    .Options(new WebhookToolOptions { ResponseTimeoutSecs = 10, PreToolSpeech = "force" });

var refund = Tool.Webhook("issue_refund", "Refund an order the caller asked to return")
    .Post("https://api.example.com/refunds")
    .Body(
        Schema.Object()
            .Property("order_id", Schema.String().FromVariable("order_id"))
            .Property("reason", Schema.String().Describe("Why the caller wants a refund").Choices("damaged", "late", "other"))
            .Property("note", Schema.String().Describe("Anything else the caller said").Optional())
    );

var transfer = SystemTool.TransferToNumber()
    .Transfer("Caller asks for billing", Destination.Phone("+15551234567"))
    .Transfer(
        "Caller asks for a manager",
        Destination.SipVariable("manager_sip"),
        new SystemTransferOptions { TransferType = "sip_refer" }
    );

var client = new ElevenLabsClient();
var created = await client.Agents.Tools.CreateAsync(new CreateToolsRequest { Body = getOrder.Build() });
File.WriteAllText("tool_configs/issue_refund.json", refund.ToJsonString());
var builtInTools = new BuiltInToolsInput { TransferToNumber = transfer.BuildConfig() };
  • Every literal param needs exactly one value source: Describe (the LLM provides it), FromVariable, Constant, SystemProvided or Omit. Properties are required unless marked Optional().
  • Schema values are immutable, so one schema can be shared by several tools. Schema.String(), Integer(), Number() and Bool() return a LiteralSchema, Object() an ObjectSchema and Array(items) an ArraySchema; methods that only apply to one kind live on that type.
  • Build(), BuildConfig() and ToJson() report every problem at once in a ToolValidationException, whose Issues carry stable codes such as missing_url or missing_value_source. Pass onWarning to Build() to see warnings.
  • Attach webhook and client tools to an agent by id in prompt.tool_ids. A system tool goes in prompt.built_in_tools, from BuildConfig().
  • Destination and the transfer option names are shared with the workflow builder in ElevenLabs.AgentWorkflows.
  • A loaded tool of a type the builder can't edit, such as an MCP tool, has Kind == ToolKind.Other. It round-trips unchanged, and Build() warns with unknown_tool_type.

Agents as code

ElevenLabs.AgentBuilder.Agent puts an agent's settings, tools and workflow in one definition. client.Agents.PushAsync creates or updates every webhook and client tool it uses, then the agent, with the tools' ids filled in:

using ElevenLabs;
using ElevenLabs.AgentBuilder;
using ElevenLabs.AgentTools;
using ElevenLabs.AgentWorkflows;
using Tool = ElevenLabs.AgentTools.Tool;

var getOrder = Tool.Webhook("get_order", "Look up an order by its number")
    .Get("https://api.example.com/orders/{order_id}")
    .PathParam("order_id", Schema.String().Describe("The order number, e.g. A-1042"));

var wf = new Workflow();
wf.Converse("triage", "Find out what the caller needs")
    .When("Caller gave an order number")
    .Tool("lookup", new[] { getOrder }) // a Tool object: push fills in its id
    .OnSuccess()
    .Converse("resolve", "Explain the order status");

var agent = new Agent("Support line", new AgentOptions
{
    Prompt = "You are a support agent for Acme.",
    FirstMessage = "Hi, how can I help?",
    VoiceId = "21m00Tcm4TlvDq8ikWAM",
    Tools = new Tool[] { SystemTool.EndCall() },
    Workflow = wf,
});

var client = new ElevenLabsClient();
var result = await client.Agents.PushAsync(agent); // creates the agent and get_order
await client.Agents.PushAsync(agent, new AgentPushOptions { AgentId = result.AgentId }); // later: updates only what changed
  • Validation first: PushAsync calls agent.Validate() before any request, so an invalid agent writes nothing. CI can call Validate() without an API key; it throws an AgentValidationException whose Issues carry stable codes such as duplicate_tool_name.
  • Tools are matched safely: with AgentId, existing tools are found among the tools that agent already uses, by name (on BranchId when given). A tool with the same name that another agent uses is never touched. Tools the agent stops using are reported as ToolPushAction.Detached, not deleted.
  • Escape hatch: ConversationConfig and PlatformSettings take any other setting, merged under the typed options. ToolIds attaches existing tools that push leaves alone. Workflow nodes take tool ids, Tool objects, or a mix (new ToolRef[] { getOrder, "tool_123" }).
  • Partial failures: if a request fails, PushAsync throws an AgentPushException whose Result lists the tools it had already created; the API error is its InnerException.
  • RequestOptions and the CancellationToken apply to every request push and pull make.

Keeping agents in git

AgentProject reads and writes the ElevenLabs CLI's project layout (agents.json, tools.json, agent_configs/, tool_configs/). The same repo works with the SDK and with elevenlabs agents push. The project records each agent's and tool's id, so running a program again updates them instead of making copies:

var project = AgentProject.Open("."); // an empty directory works too
await client.Agents.PushAsync(agent, new AgentPushOptions { Project = project }); // writes the configs and ids it pushed

// Edit an agent stored in the project
var support = project.GetAgent("Support line");
support.Update(new AgentOptions { FirstMessage = "Hello!" });
await client.Agents.PushAsync(support, new AgentPushOptions { Project = project });

// Bring an agent made in the dashboard into the repo
await client.Agents.PullAsync("agent_123", new AgentPullOptions { Project = project });

Configs are kept in API format and settings the SDK doesn't model survive a round trip. Files are written owner-only (0600), never through a symlink and never outside the project. Only JSON configs are supported for now; projects that use YAML or TOML configs raise an AgentProjectException. AgentProject.FromFiles builds a project from file contents with no I/O, and ToFiles() gives them back.

Advanced

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the MaxRetries request option to configure this behavior.

var response = await client.TextToSpeech.ConvertAsync(
    ...,
    new RequestOptions {
        MaxRetries = 0 // Override MaxRetries at the request level
    }
);

Timeouts

The SDK defaults to a 240 second timeout. Use the Timeout option to configure this behavior.

var response = await client.TextToSpeech.ConvertAsync(
    ...,
    new RequestOptions {
        Timeout = TimeSpan.FromSeconds(3) // Override timeout to 3s
    }
);

Raw Response

Access raw HTTP response data (status code, headers, URL) alongside parsed response data using the .WithRawResponse() method.

using ElevenLabs;

// Access raw response data (status code, headers, etc.) alongside the parsed response
var result = await client.Voices.SearchAsync(new SearchVoicesRequest()).WithRawResponse();

// Access the parsed data
var data = result.Data;

// Access raw response metadata
var statusCode = result.RawResponse.StatusCode;
var headers = result.RawResponse.Headers;
var url = result.RawResponse.Url;

// Access specific headers (case-insensitive)
if (headers.TryGetValue("X-Request-Id", out var requestId))
{
    Console.WriteLine($"Request ID: {requestId}");
}

Additional Headers

If you would like to send additional headers as part of the request, use the AdditionalHeaders request option.

var response = await client.Voices.SearchAsync(
    ...,
    new RequestOptions {
        AdditionalHeaders = new Dictionary<string, string?>
        {
            { "X-Custom-Header", "custom-value" }
        }
    }
);

Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the AdditionalQueryParameters request option.

var response = await client.Voices.SearchAsync(
    ...,
    new RequestOptions {
        AdditionalQueryParameters = new Dictionary<string, string>
        {
            { "custom_param", "custom-value" }
        }
    }
);

Forward Compatible Enums

This SDK uses forward-compatible enums that can handle unknown values gracefully.

using ElevenLabs;

// Using a built-in value
var outputFormat = ConvertTextToSpeechRequestOutputFormat.Mp344100128;

// Using a custom value
var customOutputFormat = ConvertTextToSpeechRequestOutputFormat.FromCustom("custom-value");

// Using in a switch statement
switch (outputFormat.Value)
{
    case ConvertTextToSpeechRequestOutputFormat.Values.Mp344100128:
        Console.WriteLine("mp3_44100_128");
        break;
    default:
        Console.WriteLine($"Unknown value: {outputFormat.Value}");
        break;
}

// Explicit casting
string outputFormatString = (string)ConvertTextToSpeechRequestOutputFormat.Mp344100128;
ConvertTextToSpeechRequestOutputFormat outputFormatFromString = (ConvertTextToSpeechRequestOutputFormat)"mp3_44100_128";

Languages Supported

Explore all models & languages.

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ElevenLabs.Net:

Package Downloads
ElevenLabs.AspNetCore

ASP.NET Core integration for the ElevenLabs .NET SDK: attach a Speech Engine server to your app's request pipeline.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 90 12/2/2026
1.0.0 125 11/26/2026