# Ako app-facing runtime API, v1. # # This file is the product: sdk/go and sdk/ts are thin clients over it, and an # app that drops both SDKs can still talk to the platform with plain HTTP. The # server side does not exist yet — this spec is what it will implement. Keep # it small: an app deployed on Ako gets identity, the team's agent, knowledge # search, file storage, notifications, and an OpenAI-compatible LLM endpoint. # Everything else stays inside the app. # # Conventions # Auth Authorization: Bearer ako_app_<...> (one key per app; server-side only) # Headers X-Ako-SDK: go/0.1.0 | ts/0.1.0 (client-reported); X-Request-Id echoed back # Errors every non-2xx body is {"error":{"code","message","request_id"}} # Retries clients retry ONLY 429 and 503, honoring Retry-After, at most 3 times # Naming snake_case on the wire; ids are opaque strings; times are RFC 3339 UTC openapi: 3.1.0 info: title: Ako Runtime API version: 0.1.0 summary: What an app deployed on Ako can call at runtime. description: >- Base URL is the app's AKO_API_URL (the same origin also issues the app's X-Ako-Assertion tokens). All endpoints require the app's bearer key. license: name: Apache-2.0 identifier: Apache-2.0 servers: - url: "{apiUrl}" description: The value of AKO_API_URL for the app. variables: apiUrl: default: https://api.withako.com security: - appKey: [] tags: - { name: identity, description: Who the calling app is. } - { name: llm, description: OpenAI-compatible model access billed to the app. } - { name: agent, description: Conversations and runs with the team's agent. } - { name: knowledge, description: Search over the team's knowledge base. } - { name: files, description: Presigned upload and download of app files. } - { name: notify, description: Outbound messages over the team's channels. } paths: /v1/whoami: get: tags: [identity] operationId: whoami summary: Identify the calling app (also the connectivity check). responses: "200": description: The app, its team and agent, remaining credits, and enabled capabilities. headers: { X-Request-Id: { $ref: "#/components/headers/X-Request-Id" } } content: application/json: schema: { $ref: "#/components/schemas/Whoami" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/llm/chat/completions: post: tags: [llm] operationId: chatCompletions summary: OpenAI chat-completions passthrough, billed to the app's credits. description: >- Wire-compatible with OpenAI's /chat/completions (including tools and `stream: true` SSE chunks), so any OpenAI client works when pointed at `/v1/llm` with the app key. `model` accepts Ako ladder names — `auto`, `fast`, `strong` — which resolve server-side to the current best model with fallback; concrete model ids are accepted but not guaranteed to stay available. requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/ChatCompletionRequest" } responses: "200": description: >- A chat completion, or (when `stream` is true) an SSE stream of `chat.completion.chunk` objects terminated by a `[DONE]` sentinel. content: application/json: schema: { $ref: "#/components/schemas/ChatCompletion" } text/event-stream: schema: { type: string } "402": description: "Credits exhausted (`code: insufficient_credits`)." content: application/json: schema: { $ref: "#/components/schemas/ErrorEnvelope" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/agent/messages: post: tags: [agent] operationId: sendMessage summary: Send a message to the team's agent. description: >- Starts (or continues, via `thread_key`) a thread with the agent and queues a run. With `wait: "reply"` the request is held until the agent answers or the server's wait window (implementation-defined, on the order of 30s) elapses; on timeout the response is 202 without `reply` and the run keeps going — poll `getRun` or stream it. requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/MessageRequest" } responses: "200": description: The agent replied within the wait window. content: application/json: schema: { $ref: "#/components/schemas/MessageResponse" } "202": description: Accepted; no reply yet (`wait` was `none`, or the wait window elapsed). content: application/json: schema: { $ref: "#/components/schemas/MessageResponse" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/agent/runs/{run_id}: get: tags: [agent] operationId: getRun summary: Fetch a run, or follow it as server-sent events. parameters: - { name: run_id, in: path, required: true, schema: { type: string } } - name: stream in: query required: false description: When `1`, respond with `text/event-stream` instead of JSON. schema: { type: string, enum: ["1"] } responses: "200": description: >- The run as JSON, or (with `stream=1`) an SSE stream. Events are named via the `event:` field with a JSON `data:` payload — `status` `{status}` on each transition, `delta` `{text}` as the reply is produced, `done` `{status, reply?}` once, then the stream closes; `error` `{code, message}` replaces `done` on failure. Comment lines (`: ping`) are heartbeats. No Last-Event-ID resume: reconnect by calling this endpoint again. content: application/json: schema: { $ref: "#/components/schemas/Run" } text/event-stream: schema: { type: string } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/knowledge/search: get: tags: [knowledge] operationId: searchKnowledge summary: Semantic search over the team's knowledge base. parameters: - { name: q, in: query, required: true, schema: { type: string, minLength: 1 } } - { name: limit, in: query, required: false, schema: { type: integer, minimum: 1, maximum: 50, default: 10 } } responses: "200": description: Best matches first. content: application/json: schema: type: object required: [items] properties: items: type: array items: { $ref: "#/components/schemas/KnowledgeItem" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/files: post: tags: [files] operationId: createFile summary: Reserve a file and get a presigned upload URL. description: >- Step 1 of 3. PUT the bytes to `upload_url` with exactly the returned `headers` (plus Content-Type) and Content-Length = `size`; no bearer token — the URL is the credential. Then call commit. Uncommitted reservations expire. requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/FileCreateRequest" } responses: "201": description: Where to upload. content: application/json: schema: { $ref: "#/components/schemas/FileTicket" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/files/{file_id}/commit: post: tags: [files] operationId: commitFile summary: Mark an upload complete (step 3 of 3). parameters: - { name: file_id, in: path, required: true, schema: { type: string } } responses: "200": description: The committed file. Its id can be attached to agent messages. content: application/json: schema: { $ref: "#/components/schemas/File" } "409": description: "The object was never uploaded or its size does not match (`code: upload_incomplete`)." content: application/json: schema: { $ref: "#/components/schemas/ErrorEnvelope" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/files/{file_id}/url: get: tags: [files] operationId: fileUrl summary: Mint a short-lived download URL for a committed file. parameters: - { name: file_id, in: path, required: true, schema: { type: string } } responses: "200": description: A URL a browser can fetch directly until `expires_at`. content: application/json: schema: { $ref: "#/components/schemas/SignedUrl" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } /v1/notify: post: tags: [notify] operationId: notify summary: Deliver a message through the team's connected channels. description: >- The app never holds email or Slack credentials; the platform routes by the recipient field given. Delivery is asynchronous — the id is a receipt for support, not something to poll. requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/NotifyRequest" } responses: "202": description: Queued for delivery. content: application/json: schema: { $ref: "#/components/schemas/Delivery" } "401": { $ref: "#/components/responses/Error" } default: { $ref: "#/components/responses/Error" } components: securitySchemes: appKey: type: http scheme: bearer bearerFormat: ako_app_ description: Per-app key issued by Ako. Server-side only; rotate from the app's settings. headers: X-Request-Id: description: The client's X-Request-Id echoed back (or one the server minted). Quote it to support. schema: { type: string } responses: Error: description: >- Any non-2xx answer. Stable codes include `unauthorized` (401), `forbidden` (403), `not_found` (404), `invalid_request` (400/422), `insufficient_credits` (402), `rate_limited` (429, with Retry-After), `unavailable` (503, with Retry-After), `internal` (500). headers: X-Request-Id: { $ref: "#/components/headers/X-Request-Id" } Retry-After: description: Present on 429 and 503; delta-seconds or an HTTP-date. schema: { type: string } content: application/json: schema: { $ref: "#/components/schemas/ErrorEnvelope" } schemas: ErrorEnvelope: type: object required: [error] properties: error: type: object required: [code, message] properties: code: { type: string, description: "Stable, snake_case; branch on this." } message: { type: string, description: For humans; may change. } request_id: { type: string } Whoami: type: object required: [app_id, team_id, agent_id, credits_remaining, capabilities] properties: app_id: { type: string } team_id: { type: string } agent_id: { type: string, description: The team agent that /v1/agent talks to. } credits_remaining: { type: number, description: Team credit balance the app draws on. } capabilities: type: array description: Which of llm, agent, knowledge, files, notify are enabled for this app. items: { type: string } ChatCompletionRequest: type: object description: OpenAI chat-completions request; only the fields Ako inspects are listed, the rest pass through. required: [model, messages] additionalProperties: true properties: model: type: string description: A ladder name (`auto`, `fast`, `strong`) or a concrete model id. examples: [auto, fast, strong] messages: type: array items: type: object required: [role] additionalProperties: true properties: role: { type: string, enum: [system, user, assistant, tool] } content: {} stream: { type: boolean, default: false } max_tokens: { type: integer } temperature: { type: number } tools: { type: array, items: { type: object } } ChatCompletion: type: object description: OpenAI chat-completion object; `model` is the concrete model the ladder resolved to. additionalProperties: true properties: id: { type: string } object: { type: string, const: chat.completion } model: { type: string } choices: { type: array, items: { type: object, additionalProperties: true } } usage: { type: object, additionalProperties: true } MessageUser: type: object description: The app's end user on whose behalf the message is sent; threads and notifications are scoped to them. required: [id] properties: id: { type: string } email: { type: string, format: email } name: { type: string } MessageRequest: type: object required: [text] properties: text: { type: string, minLength: 1 } thread_key: type: string description: App-chosen key (e.g. a ticket id). Messages with the same key share a thread; omitted = a new thread. user: { $ref: "#/components/schemas/MessageUser" } wait: type: string enum: [none, reply] default: none description: "`reply` holds the request for the answer (server-capped); `none` returns 202 once queued." files: type: array description: Committed file ids to attach. items: { type: string } MessageResponse: type: object required: [run_id, thread_id] properties: run_id: { type: string } thread_id: { type: string } reply: { type: string, description: Present only on 200. } Run: type: object required: [run_id, thread_id, status, created_at, updated_at] properties: run_id: { type: string } thread_id: { type: string } status: { type: string, enum: [queued, running, completed, failed, cancelled] } reply: { type: string, description: Set once status is completed. } error: { type: string, description: Set once status is failed. } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } KnowledgeItem: type: object required: [id, title, snippet, score] properties: id: { type: string } title: { type: string } snippet: { type: string, description: "The matching passage, trimmed." } score: { type: number, description: "Relevance in [0, 1], higher is better." } FileCreateRequest: type: object required: [name, content_type, size] properties: name: { type: string } content_type: { type: string } size: { type: integer, minimum: 0, description: Exact byte length; presigned PUTs are signed over Content-Length. } FileTicket: type: object required: [file_id, upload_url, method, headers] properties: file_id: { type: string } upload_url: { type: string, format: uri } method: { type: string, const: PUT } headers: type: object description: Headers the PUT must carry verbatim (signature-bound). additionalProperties: { type: string } File: type: object required: [file_id, name, content_type, size] properties: file_id: { type: string } name: { type: string } content_type: { type: string } size: { type: integer } SignedUrl: type: object required: [url, expires_at] properties: url: { type: string, format: uri } expires_at: { type: string, format: date-time } Recipient: type: object description: Exactly one of the fields. minProperties: 1 maxProperties: 1 properties: email: { type: string, format: email } slack_user: { type: string, description: Slack member id (U…) in the team's workspace. } contact_id: { type: string, description: A contact in the team's CRM. } NotifyRequest: type: object required: [to, text] properties: to: { $ref: "#/components/schemas/Recipient" } subject: { type: string, description: Used by channels that have one (email). } text: { type: string, minLength: 1 } Delivery: type: object required: [delivery_id] properties: delivery_id: { type: string }