Lịch sử thay đổi
Mọi lần sửa trang này, mới nhất ở trên. Mở từng mục để xem đã đổi gì.
- 16/10/2026 · +44 −22 dòng
Xem thay đổi
# 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. + > **Tóm tắt** — Đăng ký, chép key test, rồi `POST /v2/jobs` kèm `model` và `style`. Nhận kết quả qua webhook có ký hoặc poll `GET /v2/jobs/{job_id}`. - 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. + Chạy style đầu tiên thành một job. 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ý {#sign-up} ⋯ ``` - ## 3. Gửi request đầu tiên {#first-request} + ## 3. Chọn style {#pick-a-style} - 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 "https://api.wandura.ai/v2/styles?model=wandura-video-v1" -H "Authorization: Bearer $WANDURA_API_KEY" + ``` + Mỗi style có `id`, `model` (`wandura-image-v1` hoặc `wandura-video-v1`), các trường nó nhận (`inputs`, mỗi trường `required` hoặc `optional`), `price` và `preview_url`. [Catalog style](https://open.wandura.ai/styles) hiện cùng danh sách kèm bản xem trước. + + ## 4. Gửi job đầu tiên {#first-request} + ```bash - curl -X POST https://api.wandura.ai/v2/styles/sty_ghibli_portrait \ + curl -X POST https://api.wandura.ai/v2/jobs \ -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"}}' + -d '{"model": "wandura-video-v1", "style": "twenty-four", "image_urls": ["https://your-bucket.example.com/u/42/photo.jpg"], "end_user_id": "user_123"}' + # HTTP 202 + # {"job_id":"run_QVqsXwr7VGSP","status":"queued","model":"wandura-video-v1","created_at":"2026-10-16T09:15:40.825Z"} ``` - Cùng lệnh đó bằng JavaScript (Node 18+) hoặc Python, không cần cài gói Wandura nào: + Cùng lệnh đó bằng JavaScript (Node 18+) hoặc Python, không cần cài gói nào của Wandura: ```ts - const res = await fetch('https://api.wandura.ai/v2/styles/sty_ghibli_portrait', { + const res = await fetch('https://api.wandura.ai/v2/jobs', { method: 'POST', headers: { ⋯ }, body: JSON.stringify({ - lane: 'priority', + model: 'wandura-video-v1', + style: 'twenty-four', + image_urls: ['https://your-bucket.example.com/u/42/photo.jpg'], end_user_id: 'user_123', - inputs: { subject: 'a girl smiling at the camera' }, }), }); - const run = await res.json(); - console.log(run.status, run.status_url); + const job = await res.json(); + console.log(job.job_id, job.status); ``` ⋯ res = requests.post( - "https://api.wandura.ai/v2/styles/sty_ghibli_portrait", + "https://api.wandura.ai/v2/jobs", headers={ "Authorization": f"Bearer {os.environ['WANDURA_API_KEY']}", ⋯ }, json={ - "lane": "priority", + "model": "wandura-video-v1", + "style": "twenty-four", + "image_urls": ["https://your-bucket.example.com/u/42/photo.jpg"], "end_user_id": "user_123", - "inputs": {"subject": "a girl smiling at the camera"}, }, ) - run = res.json() - print(run["status"], run["status_url"]) + job = res.json() + print(job["job_id"], job["status"]) ``` - 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ý](concepts.md#webhooks) khi xong. + - `Idempotency-Key` không bắt buộc nhưng nên gửi: cùng key và cùng body thì không bao giờ thành job thứ hai. Không gửi thì cùng một body trong 10 phút là cùng một job. + - `end_user_id` không bắt buộc: gửi id người dùng trong app của bạn thì giới hạn theo ngày cho từng người sẽ giữ ví của bạn. + - Body sai bị từ chối ngay bằng `422 INVALID_INPUT`, liệt kê mọi lỗi (xem [Validation](jobs.md#validation)). + - Key test trả file mẫu với giá $0; key live chạy thật và chỉ tính tiền khi job `succeeded`. - ## Hỏi kết quả {#poll} + ## 5. Nhận kết quả {#poll} + Thêm `"webhook_url": "https://your-backend.example.com/hooks/wandura"` vào lệnh gửi, Wandura sẽ POST job cuối cùng (có ký) tới đó (xem [Webhook](jobs.md#webhooks)). Hoặc poll: + ```bash - curl https://api.wandura.ai/v2/runs/run_Qk2m9XaB7Lc4 -H "Authorization: Bearer $WANDURA_API_KEY" + curl https://api.wandura.ai/v2/jobs/run_QVqsXwr7VGSP -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`. + 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. Trạng thái: `queued` → `processing` → `succeeded`, `failed`, `cancelled` hoặc `timeout` (cuối). Job `succeeded` có `output[0].url`; job `failed` hoặc `timeout` có `error` kèm `code` và `retryable`. + **Đang triển khai:** `"lane": "relax"` (rẻ hơn hoặc cùng giá, không hạn chót) và `"inputs": {…}` cho đầu vào riêng của style như `keep_audio` (xem [Lane Relax và đầu vào riêng của style](jobs.md#lane-and-inputs)). + + ## Runs (cùng động cơ) {#runs} + + Tích hợp đã dựng trên runs vẫn chạy: `POST /v2/styles/{style}` với `{"lane", "end_user_id", "inputs"}` và một `Idempotency-Key` trả về một run có `status_url` và `cancel_url`. Run mang cùng bộ chữ trạng thái với job ở trường `state`. Xem [Khái niệm](concepts.md#runs). + ## Tiếp theo {#next} - - [Khái niệm](concepts.md): run, lane, run miễn phí, webhook, giới hạn, idempotency, end-user ID. + - [Jobs API](jobs.md): mọi trường, trạng thái, lỗi, webhook và giới hạn. + - [Khái niệm](concepts.md): lane, run miễn phí, webhook, giới hạn, idempotency, end-user ID. - [Danh sách style](styles.md): mọi style kèm đầu vào và giá. - [SDK](sdks.md): client JavaScript và Python chính thức, đang preview riêng (chưa có trên npm hay PyPI). ⋯
- 16/10/2026 · +31 −18 dòng
Xem thay đổi
⋯ ``` - Với [SDK](sdks.md): + Cùng lệnh đó bằng JavaScript (Node 18+) hoặc Python, không cần cài gói Wandura nào: ```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' }, + const res = await fetch('https://api.wandura.ai/v2/styles/sty_ghibli_portrait', { + method: 'POST', + headers: { + Authorization: `Bearer ${process.env.WANDURA_API_KEY}`, + 'Content-Type': 'application/json', + 'Idempotency-Key': crypto.randomUUID(), + }, + body: JSON.stringify({ + lane: 'priority', + end_user_id: 'user_123', + inputs: { subject: 'a girl smiling at the camera' }, + }), }); - console.log(run.status, run.output?.[0]?.url); + const run = await res.json(); + console.log(run.status, run.status_url); ``` ```python - from wandura import Wandura + import os, uuid, requests - 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")) + res = requests.post( + "https://api.wandura.ai/v2/styles/sty_ghibli_portrait", + headers={ + "Authorization": f"Bearer {os.environ['WANDURA_API_KEY']}", + "Idempotency-Key": str(uuid.uuid4()), + }, + json={ + "lane": "priority", + "end_user_id": "user_123", + "inputs": {"subject": "a girl smiling at the camera"}, + }, + ) + run = res.json() + print(run["status"], run["status_url"]) ``` ⋯ - [Khái niệm](concepts.md): run, lane, run miễn phí, webhook, giới hạn, idempotency, end-user ID. - [Danh sách style](styles.md): mọi style kèm đầu vào và giá. - - [SDK](sdks.md): client JavaScript và Python chính thức làm sẵn mọi việc trên. + - [SDK](sdks.md): client JavaScript và Python chính thức, đang preview riêng (chưa có trên npm hay PyPI). - Dựng bằng AI agent? Đưa cho nó `https://api.wandura.ai/v2/openapi.json`.
- 14/10/2026 · Tạo trang