Internal HTTP plumbing for the ElevenLabs API: authenticated requests (xi-api-key header), query strings, multipart bodies, and the HttpError returned for non-2xx responses.

Per-call credentials. Every API-calling function in this package takes an optional trailing opts Map, resolved by resolve: opts first, then the elevenlabs.api.key context variable, then the defaults. Nothing from opts is written to ctx, so one run can act for many tenants and parallel flows don't share credentials. Credentials in opts are masked in call records. An api-key present but blank or null is an error, never a fallback to context.

  • api-key: the API key for this call
  • base-url: another API root, such as a proxy. It needs an api-key in the same opts: elevenlabs.api.key is never sent to a per-call URL.

Context Vars

Optional
  • elevenlabs.api.key

Functions

build-request

fn (method: Str, path: Str, additional-headers: Map, body: Any, resolved: Map): ::hot::http/HttpRequest

The outgoing HttpRequest from resolved settings (see resolve). Pure; exposed for testing.

bytes

fn (method: Str, path: Str): Bytes
fn (method: Str, path: Str, body: Any): Bytes
fn (method: Str, path: Str, body: Any, opts: Map): Bytes

Like request, but returns the verbatim response Bytes on 2xx (for audio), or an Err carrying HttpError.

error-message

fn (status: Int, body: Any): Str

Build a readable message from an ElevenLabs error status and body. Exposed for testing.

json

fn (method: Str, path: Str): Any
fn (method: Str, path: Str, body: Any): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): Any

Like request, but returns the decoded JSON body on 2xx, or an Err carrying HttpError.

multipart-close

fn (boundary: Str): Bytes

multipart-field

fn (boundary: Str, name: Str, value: Any): Bytes

One multipart/form-data text field as Bytes. Bools render as true/false; Maps and Vecs as JSON. Exposed for testing.

multipart-file

fn (boundary: Str, name: Str, filename: Str, mime-type: Str, data: Bytes): Bytes

One multipart/form-data file part as Bytes. The file bytes are concatenated verbatim, never interpolated into a string. Exposed for testing.

non-blank

fn (value: Any): Str?

path-segment

fn (value: Str): Str

Percent-encode one path segment (a voice or history item id).

query-string

fn (params: Map): Str

Build a query-string suffix (?a=1&b=2, or "" when nothing is set) from a Map. Null values are dropped, Bools render as true/false, Vec values repeat the key, and keys and values are percent-encoded.

Example

::elevenlabs::api/query-string({page_size: 20, search: "narrator", voice_type: null})
// "?page_size=20&search=narrator"

request

fn (method: Str, path: Str): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, key: Str?): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): ::hot::http/HttpResponse

Make an authenticated request to the ElevenLabs API. path is relative to the API root (e.g. /v1/voices). ElevenLabs authenticates with an xi-api-key header (not a Bearer token). A Map or typed record body is sent as JSON (unset optional fields omitted); Bytes are sent verbatim (set Content-Type in additional-headers); "" sends no body. Returns the raw HttpResponse; json and bytes unwrap it.

Example

response ::elevenlabs::api/request("GET", "/v1/voices")
response.body.voices

request-stream

fn (method: Str, path: Str, additional-headers: Map, body: Any): ::hot::http/StreamingHttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, key: Str?): ::hot::http/StreamingHttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): ::hot::http/StreamingHttpResponse

Make an authenticated streaming request with raw (binary chunk) framing, used for streaming audio endpoints.

resolve

fn (opts: Map): Map

Credentials and settings for one call (see resolve-from). An api-key from opts is masked in this run's records and never written to ctx.

Example

::elevenlabs::api/resolve({api-key: "tenant-b-key"}).base-url  // "https://api.elevenlabs.io"
Context Vars: elevenlabs.api.key

resolve-from

fn (opts: Map, ctx-values: Map): Map

The one resolver, pure: {api-key, base-url} for a call from opts first, then ctx-values (a Map of context variables), then defaults. An Err when no API key is set, when api-key is in opts but blank or null (that never falls back to context), or when opts has base-url without api-key. Exposed for testing; resolve feeds it the context.

Types

HttpError

HttpError type {
    status: Int,
    headers: Map?,
    body: Any?,
    message: Str
}

A non-2xx ElevenLabs response. message is a readable summary of ElevenLabs' error body (detail.status/detail.message, a plain detail string, or a validation-error list); body keeps the decoded payload.