ExDaytona.Platform (ex_daytona v0.3.0)

Copy Markdown View Source

Read-only platform lookups commonly needed before creating a sandbox: organizations, regions, sandbox classes, snapshots, and usage/quota.

{:ok, regions} = ExDaytona.Platform.regions(client)
{:ok, classes} = ExDaytona.Platform.sandbox_classes(client, org_id)
{:ok, %{items: snapshots}} = ExDaytona.Platform.snapshots(client, limit: 10)

All helpers return normalized generated models with facade error handling. Note that organizations/1 requires JWT authentication — plain API keys receive a 401 from the provider.

Summary

Functions

List the caller's organizations.

List the regions available to the caller.

List the sandbox classes (with GPU availability) an organization can use.

Fetch one snapshot by id or name.

List snapshots with pagination. Accepts :page, :limit, :name, :sort, :order; returns {:ok, %{items: [...], page: p, total: n, total_pages: tp}}.

Aggregated metered usage for the organization over [from, to] (ISO 8601 timestamps), normalized to snake_case: {:ok, %{sandbox_count, cpu_seconds, ram_gb_seconds, disk_gb_seconds, gpu_seconds, price, first_start, last_end}}.

Usage over time as chart points (:region option narrows to one region). Each point: %{time, cpu, cpu_price, ram_gb, ram_price, disk_gb, disk_price}.

The organization's usage/quota overview (current usage vs. limits).

Per-sandbox metered usage over [from, to] — the primitive for rolling usage up into application-defined scopes (attribute sandboxes with labels at create time, list them with ExDaytona.Sandbox.list(client, labels: %{...}), then sum their rows here). Returns {:ok, [%{sandbox_id: id, cpu_seconds: n, ...}]}.

Functions

organizations(client)

@spec organizations(ExDaytona.Client.t()) ::
  {:ok, [ExDaytona.Model.Organization.t()]} | {:error, ExDaytona.Error.t()}

List the caller's organizations.

JWT only

The provider rejects API-key authentication on this endpoint (401 "Invalid credentials"). Sandbox-scoped code can read its own organization id from sandbox.info.organizationId instead.

regions(client)

@spec regions(ExDaytona.Client.t()) ::
  {:ok, [ExDaytona.Model.Region.t()]} | {:error, ExDaytona.Error.t()}

List the regions available to the caller.

sandbox_classes(client, organization_id)

@spec sandbox_classes(ExDaytona.Client.t(), String.t()) ::
  {:ok, [ExDaytona.Model.AvailableSandboxClass.t()]}
  | {:error, ExDaytona.Error.t()}

List the sandbox classes (with GPU availability) an organization can use.

snapshot(client, id_or_name)

@spec snapshot(ExDaytona.Client.t(), String.t()) ::
  {:ok, ExDaytona.Model.SnapshotDto.t()} | {:error, ExDaytona.Error.t()}

Fetch one snapshot by id or name.

snapshots(client, opts \\ [])

@spec snapshots(
  ExDaytona.Client.t(),
  keyword()
) ::
  {:ok,
   %{
     items: [ExDaytona.Model.SnapshotDto.t()],
     page: non_neg_integer() | nil,
     total: non_neg_integer() | nil,
     total_pages: non_neg_integer() | nil
   }}
  | {:error, ExDaytona.Error.t()}

List snapshots with pagination. Accepts :page, :limit, :name, :sort, :order; returns {:ok, %{items: [...], page: p, total: n, total_pages: tp}}.

usage_aggregated(client, organization_id, from, to)

@spec usage_aggregated(ExDaytona.Client.t(), String.t(), String.t(), String.t()) ::
  {:ok, map()} | {:error, ExDaytona.Error.t()}

Aggregated metered usage for the organization over [from, to] (ISO 8601 timestamps), normalized to snake_case: {:ok, %{sandbox_count, cpu_seconds, ram_gb_seconds, disk_gb_seconds, gpu_seconds, price, first_start, last_end}}.

Served by the analytics API (its own base URL — the connection is derived automatically; override via config :ex_daytona, :analytics_base_url).

usage_chart(client, organization_id, from, to, opts \\ [])

@spec usage_chart(ExDaytona.Client.t(), String.t(), String.t(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, ExDaytona.Error.t()}

Usage over time as chart points (:region option narrows to one region). Each point: %{time, cpu, cpu_price, ram_gb, ram_price, disk_gb, disk_price}.

usage_overview(client, organization_id)

@spec usage_overview(ExDaytona.Client.t(), String.t()) ::
  {:ok, ExDaytona.Model.OrganizationUsageOverview.t()}
  | {:error, ExDaytona.Error.t()}

The organization's usage/quota overview (current usage vs. limits).

usage_per_sandbox(client, organization_id, from, to)

@spec usage_per_sandbox(ExDaytona.Client.t(), String.t(), String.t(), String.t()) ::
  {:ok, [map()]} | {:error, ExDaytona.Error.t()}

Per-sandbox metered usage over [from, to] — the primitive for rolling usage up into application-defined scopes (attribute sandboxes with labels at create time, list them with ExDaytona.Sandbox.list(client, labels: %{...}), then sum their rows here). Returns {:ok, [%{sandbox_id: id, cpu_seconds: n, ...}]}.