# Azki Support Platform Public API v1 — LLM reference

Purpose: complete, compact spec for AI coding assistants integrating the Azki Support Platform into third-party websites/apps. Human guide: https://support.azki.ai/docs/support-api.md

## Scope
- Platform = product feedback (bug reports, feature requests, improvements) + maintenance notices for Azki products.
- NOT in public API: developer back office (todo handling, replies, notice publishing, settings). Do not attempt; it is only reachable via the Console admin UI.
- Consultation/help questions are auto-rejected; users needing help must email azu@azki.ai.

## Conventions
- API root = https://support.azki.ai/api/v1 (all paths below are relative to it) ; HTTPS only.
- JSON in/out (UTF-8). Timestamps = Unix epoch milliseconds.
- CORS: Access-Control-Allow-Origin: *, allowed headers: authorization, content-type. No cookies. Callable directly from browsers.
- Auth for feedback endpoints: header `Authorization: Bearer <token>`; token from POST /sessions; regex ^[A-Za-z0-9_-]{43}$; TTL 2h; on 401 create a new session.
- Error body (any non-2xx): {"error":{"code":string,"message":string}}. `message` is user-displayable Chinese text.
- Never persist the raw order number / redemption code server-side or in logs. Store token client-side only.

## Endpoints

GET /meta (no auth)
→ 200 {name, version:1, helpEmail, limits:{feedbackPerSubjectPerDay:20, lookupsPerIpPerHour:30}, fields:{title:{min:4,max:80}, content:{min:10,max:5000}, productIds:{min:1,max:10}}, docs:{human, humanMarkdown, llm, llmsTxt}}

POST /sessions (no auth)
body {type:"order"|"code", value:string(1..256)}  // code is case/separator-insensitive
→ 201 {token, expiresAt, subject:{type, preview}, banned:boolean, quota:{limit,used,remaining}, products:[{id, name, authors:[{displayName}]}]}
errors: 400 invalid_request | 404 subject_not_found (order missing/refunded, code invalid/revoked) | 429 rate_limited (30 lookups/IP/hour) | 503 upstream_unavailable

DELETE /sessions/current (Bearer) → 204

GET /feedback (Bearer)
→ 200 {subject:{type,preview}, banned, quota, items: Feedback[] (newest first, without `events`)}

POST /feedback (Bearer)
body {title:string(4..80), content:string(10..5000), email?:string|null (valid email ≤254), productIds:string[1..10] ⊆ session products[].id}
→ 201 Feedback (with events). Server waits ≤~20s for AI review; if unfinished returns status "reviewing".
errors: 400 invalid_request | 401 unauthorized | 403 subject_banned | 429 quota_exceeded (20 submissions/subject/24h, counts new+revision+continuation) | 429 rate_limited (per-IP daily cap)

GET /feedback/{id} (Bearer) → 200 Feedback (with events) | 404 not_found
id regex ^fb_[a-f0-9]{32}$

POST /feedback/{id}/revision (Bearer)  // only when status=="needs_revision"
body {title, content, email?}  (no productIds; omitted email keeps previous)
→ 200 Feedback | 409 invalid_state | quota errors as above

POST /feedback/{id}/continuation (Bearer, no body)  // only when status=="duplicate_resolved"; user asserts their issue differs from the matched resolved one → re-review, new todo created
→ 200 Feedback | 409 invalid_state | quota errors as above

GET /notices?page=1&pageSize=20&productId=<id> (no auth; pageSize ≤50)
→ 200 {page, pageSize, total, items: NoticeSummary[]} (newest first, hidden notices excluded)

GET /notices/{id} (no auth) → 200 Notice | 404 not_found
id regex ^nt_[a-f0-9]{20}$ ; HTML page: BASE/notices/{id}

## Types (TypeScript)
```ts
type FeedbackStatus = 'reviewing' | 'needs_revision' | 'rejected' | 'banned' | 'duplicate_resolved' | 'accepted'
interface Feedback {
  id: string; title: string; content: string
  email: string | null            // masked, e.g. "u***r@example.com"
  products: { id: string; name: string }[]
  authors: { displayName: string }[]   // recipients of this feedback
  status: FeedbackStatus; statusLabel: string
  message: string | null          // rejection reason or what to add (needs_revision)
  kind: 'bug' | 'feature' | 'improvement' | null; tags: string[]
  createdAt: number; updatedAt: number
  assignments: { author: { displayName: string }; read: boolean; readAt: number | null
    issueStatus: 'open' | 'completed' | 'rejected'; resolutionNote: string | null; resolvedAt: number | null }[]
  matchedIssues: { title: string; status: 'completed' | 'rejected'; resolutionNote: string | null
    resolvedAt: number | null; author: { displayName: string } }[]   // non-empty only for duplicate_resolved
  replies: { authorName: string; body: string; createdAt: number }[]
  actions: { canRevise: boolean; canContinue: boolean }
  events?: { kind: string; detail: string; createdAt: number }[]     // timeline, single-item endpoints only
}
interface NoticeSummary { id: string; title: string; author: { displayName: string }; products: { id: string; name: string }[]
  excerpt: string; createdAt: number; updatedAt: number }
interface Notice extends NoticeSummary { content: string }   // plain text with newlines; render as text, never as HTML
```

## Status semantics / required UI behavior
- reviewing → poll GET /feedback/{id} every 3–5s.
- needs_revision → show `message`; let user edit; call /revision.
- rejected → show `message` (consultation → "该平台为产品功能性反馈平台，不解答疑惑，如需帮助请发送电子邮件到azu@azki.ai"; or insufficient info). Terminal.
- banned → severe abuse; subject permanently barred from submitting. Terminal. POST /feedback returns 403 subject_banned.
- duplicate_resolved → show each matchedIssues[].resolutionNote as the author's unified reply; offer button "匹配到的问题与我反馈的问题有区别，继续提交" → /continuation.
- accepted → show assignments (read state, issueStatus, resolutionNote) and replies.
- Show `authors` before/after submission so users know which author receives the feedback (from session products[].authors for selected productIds).
- Email (optional) receives automated notices: developer first read, resolution result, developer reply. Emails are no-reply.

## Error codes
400 invalid_request · 401 unauthorized · 403 subject_banned · 404 subject_not_found · 404 not_found · 409 invalid_state · 413 payload_too_large · 429 quota_exceeded · 429 rate_limited (honor Retry-After if present) · 500 internal_error · 503 upstream_unavailable

## Minimal client (fetch)
```js
const BASE='https://support.azki.ai'
async function api(p,{token,method='GET',body}={}){const r=await fetch(BASE+p,{method,headers:{...(body?{'content-type':'application/json'}:{}),...(token?{authorization:'Bearer '+token}:{})},body:body?JSON.stringify(body):undefined});const d=r.status===204?null:await r.json();if(!r.ok)throw Object.assign(new Error(d.error.message),{code:d.error.code,status:r.status});return d}
// const s=await api('/api/v1/sessions',{method:'POST',body:{type:'order',value:orderNo}})
// let f=await api('/api/v1/feedback',{token:s.token,method:'POST',body:{title,content,email,productIds:[s.products[0].id]}})
// while(f.status==='reviewing'){await new Promise(r=>setTimeout(r,4000));f=await api('/api/v1/feedback/'+f.id,{token:s.token})}
```
