Quickstart

Prerequisites

  • Tài khoản trên dash.iai.one
  • Email và password của workspace
  • Browser hoặc HTTP client hỗ trợ cookies (credentials: "include")

Step 1 — Login

POST /api/auth/login

Gửi credentials. API trả về Set-Cookie header với session token. Cookie được tự động lưu bởi browser.

Request
POST https://api.flow.iai.one/api/auth/login
Content-Type: application/json

{
  "email": "you@company.com",
  "password": "your-password"
}
Response 200
{
  "authenticated": true,
  "user": {
    "id": "usr_...",
    "email": "you@company.com",
    "name": "Your Name"
  },
  "workspace": {
    "workspaceId": "ws_...",
    "name": "My Workspace",
    "role": "owner"
  }
}
Cookie iai_session được set với HttpOnly; Secure; SameSite=None. Mọi request sau chỉ cần credentials: "include".

Step 2 — Verify Session

GET https://api.flow.iai.one/api/auth/session
// credentials: "include"
Response 200
{
  "authenticated": true,
  "user": { ... },
  "workspace": { ... }
}

Step 3 — List Flows

GET https://api.flow.iai.one/api/flows
// credentials: "include"
Response 200
{
  "items": [
    {
      "id": "wf_...",
      "name": "My Flow",
      "status": "active",
      "version": 1,
      "updated_at": "2026-01-01T00:00:00Z"
    }
  ]
}

Step 4 — Run a Flow

POST https://api.flow.iai.one/api/workflows/{id}/run
Content-Type: application/json
// credentials: "include"

{
  "input": { "topic": "AI trends 2026" }
}
Response 200
{
  "run_id": "run_...",
  "status": "running",
  "started_at": "2026-01-01T00:00:00Z"
}

Step 5 — Poll Run Status

GET https://api.flow.iai.one/api/runs/{run_id}
// credentials: "include"
Response 200
{
  "run": {
    "id": "run_...",
    "status": "success",
    "duration_ms": 1240,
    "output": { ... }
  }
}
Note: Runs có thể mất vài giây đến vài phút. Poll mỗi 1-2 giây cho đến khi statussuccess hoặc failed.

JavaScript Example (Browser)

const API = "https://api.flow.iai.one";

// 1. Login
const login = await fetch(`${API}/api/auth/login`, {
  method: "POST",
  credentials: "include",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ email, password })
}).then(r => r.json());

// 2. List flows
const { items: flows } = await fetch(`${API}/api/flows`, {
  credentials: "include"
}).then(r => r.json());

// 3. Run first flow
const run = await fetch(`${API}/api/workflows/${flows[0].id}/run`, {
  method: "POST",
  credentials: "include",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ input: {} })
}).then(r => r.json());

console.log("Run ID:", run.run_id);

Next Steps