# list_templates

> List the templates run_template can run

`GET /api/v2/templates`

Each template says what inputs it needs (name, type, required) and a rough price. Pass `dry_run: true` to run_template for the exact price. Needs the `generate` scope.

- Auth: API key (Authorization: Bearer)
- Key scope needed: `generate`
- Raw spec: https://app.diffusr.ai/api/v2/openapi.json

## Example

**cURL**

```bash
curl "https://app.diffusr.ai/api/v2/templates" \
  -H "Authorization: Bearer $DIFFUSR_KEY"
```

**TypeScript**

```ts
import { Diffusr } from "diffusr";

const d = new Diffusr(); // reads DIFFUSR_KEY
const { templates } = await d.listTemplates();
console.log(templates.map((t) => t.id));
```

**Python**

```python
from diffusr import Diffusr

d = Diffusr()  # reads DIFFUSR_KEY
data = d.list_templates()
print([t["id"] for t in data["templates"]])
```

## Response

### 200 ApiTemplateList

Templates run_template can run, with the inputs each needs.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `templates` | object[] | yes |  |
| `templates[].id` | string | yes | Pass this as `template` to run_template. |
| `templates[].name` | string | yes |  |
| `templates[].kind` | "product_ad" \| "video_template" \| "talking_head" \| "podcast" | yes |  |
| `templates[].about` | string | yes |  |
| `templates[].inputs` | object[] | yes |  |
| `templates[].inputs[].name` | string | yes | The run_template field this fills (a dotted name like `pictures.<slot>` is a key inside that field). |
| `templates[].inputs[].type` | string | yes | What it takes, e.g. "text", "image_url", "video_url", "image_urls". |
| `templates[].inputs[].required` | boolean | yes |  |
| `templates[].inputs[].about` | string | yes |  |
| `templates[].price_hint` | object | no | A rough price. The exact one comes from run_template with dry_run: true. |
| `templates[].price_hint.credits` | number | yes |  |
| `templates[].price_hint.approximate` | true | yes |  |

## Errors

Every error body is `{ error, code, request_id, ... }`. See https://diffusr.ai/docs/errors.

- 401: Missing, wrong, revoked or expired API key (code UNAUTHORIZED, KEY_REVOKED, KEY_EXPIRED).
- 403: The key may not do this (SCOPE_DENIED, MODEL_NOT_ALLOWED, TEST_MODE_UNSUPPORTED, ACCOUNT_BLOCKED, allowance_exceeded).
- 429: Too many requests or jobs (RATE_LIMITED, CONCURRENCY_LIMIT, UPLOAD_QUOTA, …). Wait Retry-After seconds, then retry.
- 500: Our fault (INTERNAL_ERROR). Quote request_id to support.
- 503: Paused or busy (API_PAUSED, MODEL_PAUSED, PROVIDER_PAUSED, PROVIDER_BUSY, UNAVAILABLE). Wait Retry-After seconds, then retry.

## Charges

Free. No credits are spent.
