# Bắt đầu nhanh

> **Tóm tắt** — Đăng ký, chép key test, gửi một request kèm `Idempotency-Key` và `end_user_id`. Poll `status_url` đến khi run kết thúc.

Chạy style đầu tiên trong ba bước. Lệnh gọi đi từ máy chủ của bạn tới `https://api.wandura.ai` kèm API key.

## 1. Đăng ký
[Đăng ký](https://open.wandura.ai/login) bằng email. Bạn có tài khoản cá nhân, một product **Test** với key test, và một product **My app** để chạy thật.

## 2. Lấy key
Key test (`wdr_test_…`) hiện một lần khi đăng ký. Key test trả kết quả mẫu với giá **$0**, nên bạn dựng xong cả tích hợp trước khi nạp tiền. Key live (`wdr_live_…`) chạy thật và trừ ví của product. Giữ key trên máy chủ:

```bash
export WANDURA_API_KEY=wdr_test_...
```

## 3. Gửi request đầu tiên
Mỗi lần gửi cần header `Idempotency-Key` và `end_user_id` (người dùng trong app của bạn) trong body.

```bash
curl -X POST https://api.wandura.ai/v2/styles/sty_ghibli_portrait \
  -H "Authorization: Bearer $WANDURA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"lane": "priority", "end_user_id": "user_123", "inputs": {"subject": "a girl smiling at the camera"}}'
```

Với [SDK](https://docs.wandura.ai/vi/developers/api-v2/sdks):

```ts
import { Wandura } from '@wandura/sdk';

const wandura = new Wandura(); // reads WANDURA_API_KEY
const run = await wandura.runs.createAndWait('sty_ghibli_portrait', {
  lane: 'priority',
  end_user_id: 'user_123',
  inputs: { subject: 'a girl smiling at the camera' },
});
console.log(run.status, run.output?.[0]?.url);
```

```python
from wandura import Wandura

wandura = Wandura()  # reads WANDURA_API_KEY
run = wandura.runs.create_and_wait("sty_ghibli_portrait", {
    "lane": "priority",
    "end_user_id": "user_123",
    "inputs": {"subject": "a girl smiling at the camera"},
})
print(run["status"], run.get("output"))
```

Phản hồi là một run có `request_id`, `status_url` và `cancel_url`. Poll `status_url` hoặc nhận [webhook có ký](https://docs.wandura.ai/vi/developers/api-v2/concepts#webhooks) khi xong.

## Hỏi kết quả
```bash
curl https://api.wandura.ai/v2/runs/run_Qk2m9XaB7Lc4 -H "Authorization: Bearer $WANDURA_API_KEY"
```

Priority: bắt đầu ở **2 s**, nhân 1.5 mỗi lần, tối đa **10 s**, cộng thêm 0–0.5 s ngẫu nhiên. Relax: 10 s đến 60 s. Trạng thái cuối: `completed`, `failed`, `nsfw`, `canceled`.

## Tiếp theo
- [Khái niệm](https://docs.wandura.ai/vi/developers/api-v2/concepts): run, lane, run miễn phí, webhook, giới hạn, idempotency, end-user ID.
- [Danh sách style](https://docs.wandura.ai/vi/developers/api-v2/styles): mọi style kèm đầu vào và giá.
- [SDK](https://docs.wandura.ai/vi/developers/api-v2/sdks): client JavaScript và Python chính thức làm sẵn mọi việc trên.
- Dựng bằng AI agent? Đưa cho nó `https://api.wandura.ai/v2/openapi.json`.
