# `Aigifmaker`
[🔗](https://github.com/hanshs474/aigifmaker-ex/blob/main/lib/aigifmaker.ex#L1)

Official Elixir SDK for [AI GIF Maker](https://aigifmaker.ai): turn text into
animated GIFs.

    {:ok, url} = Aigifmaker.generate("a corgi in sunglasses dancing on a beach")
    {:ok, left} = Aigifmaker.credits()

Pass `api_key:` or set `AIGIFMAKER_API_KEY`; create a key at
https://aigifmaker.ai/settings/apikeys. Each GIF costs 1 credit on your
AI GIF Maker account, the same as on the website.

Failures are `{:error, reason, message}` where `reason` is `:auth`, `:quota`,
`:rejected`, `:failed`, `:timeout` or `:other`.

Options for every call: `:api_key`, `:base_url` (`"https://aigifmaker.ai"`),
`:timeout` (milliseconds `generate/2` and `wait/2` keep polling, 15 minutes),
`:poll_ms` (3000).

Uses only `:httpc` from OTP and the standard `JSON` module; no dependencies.

# `error`

```elixir
@type error() :: {:error, reason(), String.t()}
```

# `reason`

```elixir
@type reason() :: :auth | :quota | :rejected | :failed | :timeout | :other
```

# `credits`

```elixir
@spec credits(keyword()) :: {:ok, integer()} | error()
```

Remaining credits on the account. Free to call.

# `generate`

```elixir
@spec generate(String.t(), keyword()) :: {:ok, String.t()} | error()
```

Generates one animated GIF and returns its URL.

# `status`

```elixir
@spec status(String.t(), keyword()) :: {:ok, map()} | error()
```

Returns the task record: a map with `"id"`, `"status"` (`"pending"`,
`"processing"`, `"success"` or `"failed"`), `"images"` (the GIF URL first,
once it succeeds) and, while an account without purchased credits waits its
turn, `"queued" => true`.

# `submit`

```elixir
@spec submit(String.t(), keyword()) :: {:ok, String.t()} | error()
```

Starts one GIF and returns its task id without waiting.

# `unwrap`

```elixir
@spec unwrap(integer(), term()) :: {:ok, map()} | error()
```

Turns a response envelope into `{:ok, data}` or the error that says what to
do next. Every response is HTTP 200; the JSON `code` tells success from refusal.

# `wait`

```elixir
@spec wait(String.t(), keyword()) :: {:ok, String.t()} | error()
```

Polls a task every 3 seconds until it finishes and returns the GIF URL.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
