Bunnyx (Bunnyx v0.3.1)

Copy Markdown View Source

Elixir client for the bunny.net API.

Which client do I need?

bunny.net has several services with different authentication and base URLs. Each gets its own client:

ClientAuthUse for
Bunnyx.new/1Account API keyCDN, DNS, storage zones, video libraries, billing, shield, edge scripting, magic containers
Bunnyx.Storage.new/1Storage zone passwordFile upload/download/delete in edge storage
Bunnyx.S3.new/1Zone name + password (SigV4)S3-compatible storage operations
Bunnyx.Stream.new/1Library API keyVideo CRUD, upload, collections, captions

Most users only need Bunnyx.new/1. Use the others when working directly with files (Storage/S3) or videos (Stream).

Creating a client

client = Bunnyx.new(api_key: "sk-...")

The client holds a configured Req.Request struct. Reuse it across calls to share the connection pool:

{:ok, zones} = Bunnyx.PullZone.list(client)
{:ok, zone}  = Bunnyx.PullZone.get(client, 12345)

For one-off calls, you can pass options directly — a throwaway client is created:

{:ok, zones} = Bunnyx.PullZone.list(api_key: "sk-...")

Error handling

All functions return {:ok, result} or {:error, %Bunnyx.Error{}}. The error struct includes the HTTP status code (or nil for network errors) and a message.

Main API modules (use Bunnyx.new/1)

Separate client modules

  • Bunnyx.Storage — edge storage file operations (own auth + base URL)
  • Bunnyx.S3 — S3-compatible storage with AWS SigV4 signing
  • Bunnyx.Stream — video CRUD, upload, collections, captions (own auth + base URL)

Summary

Functions

Creates a new API client.

Types

t()

@type t() :: %Bunnyx{req: Req.Request.t()}

Functions

new(opts)

@spec new(keyword()) :: t()

Creates a new API client.

Options

  • :api_key (required) — your bunny.net API key
  • :receive_timeout — default socket receive timeout in milliseconds
  • :finch — a custom Finch pool name
  • :req_opts — additional Req options merged into the request (e.g. [redirect: false])

Examples

client = Bunnyx.new(api_key: "sk-...")

# With custom timeout and Req options
client = Bunnyx.new(api_key: "sk-...", receive_timeout: 30_000, req_opts: [retry: false])