# ASOP API Quickstart

Generate an ASOP token and call chat, KREA2, REDQW21 (Qwen Image 2.1), and listed reference-to-video models. Credits share the Create-page wallet.

## Get your API token

Open https://asop.uk/api and generate a token. Format: `asop-` + 32 hex characters.

Save it locally or download the JSON / Agent Skill. The site list stays masked; use View to reveal again.

## Set up your API key

```bash
export ASOP_API_KEY='asop-your-token-here'
```

Or in `.env`:

```
ASOP_API_KEY=asop-your-token-here
```

## Install the SDK

```bash
pip install openai
```

```bash
npm install openai
```

Base URL: `https://asop.uk/api/v1`

## Chat

Model: `prompt-assist`. Endpoint: `POST /chat/completions`. Overseas content policy. Reverse-prompt: attach `image_url` parts on a user message.

```python
import os
from openai import OpenAI

client = OpenAI(api_key=os.getenv("ASOP_API_KEY"), base_url="https://asop.uk/api/v1")
print(client.chat.completions.create(
    model="prompt-assist",
    messages=[{"role": "user", "content": "A wet neon alley at 2 a.m."}],
).choices[0].message.content)
```

Streaming: set `stream=true`. Optional: `max_tokens` (16–4096, default 1024), `temperature` (default 0.7), `top_p`.

## Async image (KREA2)

`heishou-krea2` returns a job. Poll `GET /jobs/{id}`.

```python
import os, time, requests

base = "https://asop.uk/api/v1"
headers = {"Authorization": f"Bearer {os.environ['ASOP_API_KEY']}"}
job = requests.post(f"{base}/jobs", headers=headers, json={
    "model": "heishou-krea2",
    "prompt": "Portrait still, 2:3",
    "aspect_ratio": "2:3",
    "image_resolution": "6MP",
    "krea2Mode": "story",
}).json()
while True:
    row = requests.get(f"{base}/jobs/{job['id']}", headers=headers).json()
    if row["status"] in ("completed", "failed"):
        break
    time.sleep(4)
print(row.get("output") or row.get("error"))
```

## REDQW21 / Qwen Image 2.1

Canonical ID: `redqw21-unlocked`. Aliases: `qwenimage2.1`, `qwen-image-2.1`, `qw21`, `redqw21`. Requires the paid pack. Resolutions: `1.5MP` / `4MP` / `8MP`.

```python
job = requests.post(f"{base}/jobs", headers=headers, json={
    "model": "qwenimage2.1",
    "prompt": "Portrait still, 2:3",
    "aspect_ratio": "2:3",
    "image_resolution": "1.5MP",
    "imageGenMode": "txt2img",
    "redqw21PromptEnhance": True,
}).json()
```

Edit/ref: `POST /files` then pass `"images": ["file_…"]` and `imageGenMode` `edit` or `ref`.

## Video

`POST /files` then `POST /videos/generations` with `images` / `videos` / `audios` file IDs. `heishou-h3` `h3Mode`: `hd` | `fast` | `raw` | `series`.

## Models

`GET /models` lists currently available IDs (not a fixed nine). Typical:

| Model ID | Access | Typical call |
| --- | --- | --- |
| `prompt-assist` | `POST /chat/completions` | chat · max_tokens 1024 |
| `heishou-krea2` | `POST /jobs` | image · 2:3 · 6MP |
| `redqw21-unlocked` | `POST /jobs` | image · 2:3 · 1.5MP · pack |
| `heishou-h3` | `POST /videos/generations` | video · 2:3 · 10s · 3MP / raw 768P |
| `hongchao-h3` | `POST /videos/generations` | video · 10s · 768P · stricter policy |

Live credit quotes: https://asop.uk/docs/getting-started/quick-start or `GET /api/asop/docs/quotes`.

## Credits

Same wallet as the Create page. Ledger rows are tagged Demo or API and name the model. `402` = insufficient credits. Failed generations are refunded.

## Next

- https://asop.uk/docs/api-reference
- https://asop.uk/docs/llms.txt
