RevelryAI.V2.ApiJob (RevelryAI v0.3.0)

Copy Markdown View Source

Handles polling of asynchronous API jobs for the RevelryAI v2 API.

Jobs are created by async v2 endpoints such as RevelryAI.V2.Skill.run/4 and progress from "pending" to "running" to either "completed" or "failed". Once completed, the job's "content" holds the AI output; on failure, "error_message" describes what went wrong.

Summary

Functions

Polls an API job until it reaches a terminal status ("completed" or "failed") or the timeout elapses.

Retrieves an API job by its ID.

Functions

await(api_job_id, opts \\ [])

@spec await(integer(), Keyword.t()) :: {:ok, map()} | {:error, term()}

Polls an API job until it reaches a terminal status ("completed" or "failed") or the timeout elapses.

A failed job is still a successful poll: it is returned as {:ok, response} and callers should branch on the job's "status" and "error_message".

Parameters

  • api_job_id: the ID of the API job
  • opts (optional): polling options plus any configuration overrides:
    • interval: milliseconds between polls (default 2000)
    • timeout: overall deadline in milliseconds (default 120000)
    • any other keys are treated as configuration overrides (e.g. api_key)

Example

iex> RevelryAI.V2.ApiJob.await(42, timeout: 300_000)
{:ok, %{status: "ok", response: %{"id" => 42, "status" => "completed", "content" => "..."}}}

Returns

{:ok, response} once the job is completed or failed, {:error, :timeout} if the deadline elapses first, or {:error, reason} on a request error.

get(api_job_id, config \\ [])

@spec get(integer(), Keyword.t()) :: {:ok, map()} | {:error, term()}

Retrieves an API job by its ID.

Parameters

  • api_job_id: the ID of the API job
  • config (optional): a configuration keyword list used to override default config values

Example

iex> RevelryAI.V2.ApiJob.get(42)
{:ok,
 %{
   status: "ok",
   response: %{
     "id" => 42,
     "type" => "skill_run",
     "status" => "completed",
     "project_id" => 1,
     "chat_id" => nil,
     "metadata" => %{"skill_id" => 10},
     "content" => "The generated output.",
     "error_message" => nil,
     "inserted_at" => "2026-07-15T00:00:00Z",
     "updated_at" => "2026-07-15T00:00:30Z"
   }
 }}