# Podfactum API — for coding agents

Turn a URL or PDF into a podcast episode in the account owner's Podfactum feed.

- Base URL: `https://podfactum.com`
- Auth: `Authorization: Bearer pfk_...` on every request. The human gets keys at
  `https://podfactum.com/user/settings/api`.
- Machine-readable spec: `GET /api/v1/openapi.json` (OpenAPI 3.1)
- Errors: RFC 9457 `application/problem+json`. Branch on the stable `code` field.

## Submit a URL

```bash
curl -sS https://podfactum.com/api/v1/submissions \
  -H "Authorization: Bearer $PODFACTUM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/article"}'
```

## Submit a PDF

```bash
curl -sS https://podfactum.com/api/v1/submissions \
  -H "Authorization: Bearer $PODFACTUM_API_KEY" \
  -F "file=@paper.pdf"
```

Both return `202 Accepted`:

```json
{"id": "…", "status": "pending", "status_url": "https://podfactum.com/api/v1/submissions/…", "episode": null, "error": null}
```

If the content already exists (deduplicated), you get `200` immediately with
`"status": "completed"`, `"deduplicated": true`, and the `episode` filled in —
no `status_url`, nothing to poll, no credit spent.

## Poll until done

`GET {status_url}` with the same auth header. Generation typically takes a few
minutes; poll every 30–60 seconds. `status` walks `pending → processing →
completed` (or `failed`, with `error.detail` explaining why).

On `completed`:

```json
{"status": "completed", "episode": {"title": "…", "share_url": "https://podfactum.com/e/XXXXXXXX", "audio_url": "https://…/….mp3", "duration_seconds": 812}, "error": null}
```

`share_url` is a public web page; `audio_url` is the MP3 itself.

## Errors you must handle

| Status | `code` | What to do |
|---|---|---|
| 401 | `invalid_api_key` | The key is missing, wrong, or revoked. Ask the human for a new one. |
| **402** | `out_of_credits` | Stop submitting. Tell the human to buy episodes at podfactum.com/user/settings. Retrying will not help. |
| 409 | `duplicate_submission` | Already submitted. The body's `submission_id` is pollable at `/api/v1/submissions/{submission_id}` — treat as success. |
| 413 | `pdf_too_large` | PDFs are capped at 100 MB. |
| 415 | `unsupported_media_type` | Only PDFs as files; only `application/json` or `multipart/form-data` bodies. |
| 422 | `invalid_request` | Fix the request shape; `detail` says what's wrong. |

A `202` can also come back with `"status": "failed"` and
`error.detail` saying you were **not charged** — that means the queue was
briefly unavailable; retry the same submission after a minute.

Do not retry 4xx responses unchanged. There is no idempotency header — resubmitting
the same URL or PDF is safe by design (you'll get the 409 with the existing id).
