> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mynth.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Image Alt Text

> Use POST /image/alt or the SDK to generate short alt text for one or more images by URL.

The `/image/alt` endpoint accepts up to 10 image URLs and returns concise alt text for each one. By default the response is synchronous - results are returned in the same HTTP response, not via polling. Set `"sync": false` to queue the task asynchronously and receive a `202` with a task ID instead.

## Pricing

`/image/alt` is priced at **\$0.0004 per image**. Only images that successfully receive alt text are charged.

The full amount for all submitted URLs is reserved up front. If a URL fails, the unused reserve for that image is released.

## Generate alt text with the SDK

```ts theme={"theme":"kanagawa-dragon"}
import Mynth from "@mynthio/sdk";

const mynth = new Mynth();

const result = await mynth.image.alt({
  urls: ["https://example.com/photo.webp"],
});

console.log(result.getAltTexts());
```

`getAltTexts()` returns only successful items. Use `getErrors()` to inspect failed URLs.

```ts theme={"theme":"kanagawa-dragon"}
for (const item of result.results) {
  if (item.status === "failed") {
    console.error("Failed to generate alt text:", item.url, item.error.code);
  } else {
    console.log(item.url, item.alt);
  }
}
```

## Generate alt text with REST

```bash theme={"theme":"kanagawa-dragon"}
curl https://api.mynth.io/image/alt \
  -X POST \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": [
      "https://example.com/photo-1.webp",
      "https://example.com/photo-2.webp"
    ]
  }'
```

Response:

```json theme={"theme":"kanagawa-dragon"}
{
  "data": {
    "task": {
      "id": "tsk_01KE7XWWEQ4MCGWKBQKJ1G47RP",
      "status": "completed",
      "cost": "0.00080000"
    },
    "results": [
      {
        "status": "success",
        "url": "https://example.com/photo-1.webp",
        "alt": "A ceramic mug on a wooden table beside a window."
      },
      {
        "status": "success",
        "url": "https://example.com/photo-2.webp",
        "alt": "A red hiking backpack on a rocky mountain trail."
      }
    ]
  }
}
```

## Start now, wait later

Use `altAsync()` in the SDK when you want to create the task now and wait later:

```ts theme={"theme":"kanagawa-dragon"}
const task = await mynth.image.altAsync({
  urls: ["https://example.com/photo.webp"],
});

console.log(task.id);

const result = await task.wait();
console.log(result.getAltTexts());
```

For REST, set `"sync": false`:

```json theme={"theme":"kanagawa-dragon"}
{
  "urls": ["https://example.com/photo.webp"],
  "sync": false
}
```

The API returns a `202` pending response with a task ID. Poll `/tasks/:id/status` and `/tasks/:id/result`, or listen for the `task.image.alt.completed` webhook.
