Fullstack

API Reference

This page documents the HTTP endpoints exposed by the Aomi backend. All endpoints are relative to your backend URL (e.g., https://api.aomi.dev).

Authentication

Most endpoints require two headers:

HeaderDescription
X-Session-IdUUID identifying the conversation session
X-API-KeyYour Aomi API key (required for non-default apps)

Endpoints


Create Session

Create a new chat session.

POST /api/sessions

Headers:

HeaderRequiredValue
X-Session-IdYesUUID for the new session

Response:

{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "created": true
}

Get Session

Fetch details for an existing session.

GET /api/sessions/{id}

Path Parameters:

ParameterTypeDescription
idstringSession UUID

Response:

{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "threads": [
    {
      "id": "thread-uuid",
      "title": "ETH Price Discussion",
      "created_at": "2025-01-15T10:30:00Z",
      "updated_at": "2025-01-15T11:00:00Z"
    }
  ]
}

Send Message (Chat)

Send a message to the AI assistant. Returns a Server-Sent Events (SSE) stream.

POST /api/chat?app={app}

Query Parameters:

ParameterRequiredDescription
appNoTarget app (defaults to default)

Headers:

HeaderRequiredDescription
X-Session-IdYesSession UUID
X-API-KeyFor non-default appsYour API key
Content-TypeYesapplication/json

Request Body:

{
  "text": "What is the current price of ETH?"
}

Response: SSE stream (text/event-stream)

data: {"type":"text","content":"The current "}

data: {"type":"text","content":"price of ETH is "}

data: {"type":"tool_call","name":"GetTokenPrice","call_id":"call_1","args":{"symbol":"ETH"}}

data: {"type":"tool_result","call_id":"call_1","name":"GetTokenPrice","result":{"price":3500.00}}

data: {"type":"text","content":"$3,500.00."}

data: {"type":"complete"}

SSE Event Types:

TypeDescriptionFields
textIncremental text from the LLMcontent
tool_callThe assistant is calling a toolname, call_id, args
tool_resultResult from a tool executioncall_id, name, result
async_tool_resultResult from a multi-step toolcall_id, name, result
completeResponse generation finished--
errorAn error occurredmessage

Get Session State

Get the current state snapshot for a session. Useful for polling session status and receiving pending updates.

GET /api/state?session_id={session_id}

Query Parameters:

ParameterRequiredDescription
session_idYesSession UUID

Response:

{
  "session_id": "550e8400-...",
  "status": "idle",
  "messages": [],
  "user_state": {
    "address": "0x742d...",
    "chain_id": 1,
    "is_connected": true
  }
}

Interrupt Generation

Cancel an in-progress response generation.

POST /api/interrupt?session_id={session_id}

Query Parameters:

ParameterRequiredDescription
session_idYesSession UUID

Response:

{
  "interrupted": true
}

Subscribe to Updates

Subscribe to real-time updates for a session via SSE. This is a long-lived connection that receives system events, async tool results, and state changes.

GET /api/updates

Headers:

HeaderRequiredDescription
X-Session-IdYesSession UUID

Response: SSE stream with system events.


Control Actions

Perform control actions on a session (e.g., select a model).

POST /api/control/{action}?session_id={session_id}

Path Parameters:

ParameterDescription
actionThe control action to perform (e.g., model)

Query Parameters:

ParameterRequiredDescription
session_idYesSession UUID

Request Body: Varies by action.

For model selection:

{
  "model": "claude-sonnet"
}

Response:

{
  "success": true
}

List Available Models

Get the list of models available for the current session.

GET /api/session/models

Response:

{
  "models": [
    {
      "id": "claude-sonnet",
      "name": "Claude Sonnet",
      "provider": "anthropic"
    },
    {
      "id": "gpt-4o",
      "name": "GPT-4o",
      "provider": "openai"
    }
  ]
}

List Authorized Apps

Get the apps your API key is authorized to access.

GET /api/session/apps

Headers:

HeaderRequiredDescription
X-API-KeyYesYour API key

Response:

{
  "apps": [
    {
      "id": "mycoindex",
      "name": "MyCoinDex"
    },
    {
      "id": "default",
      "name": "Default"
    }
  ]
}

SSE Stream Format

All SSE responses follow the standard format:

data: {json}\n\n

Each line starts with data: followed by a JSON object and ends with two newlines. The JSON object always contains a type field that determines how to process the event.

Consuming SSE in JavaScript

const response = await fetch("/api/chat?app=mycoindex", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Session-Id": sessionId,
    "X-API-Key": apiKey,
  },
  body: JSON.stringify({ text: "Hello" }),
});

const reader = response.body!.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const chunk = decoder.decode(value);
  const lines = chunk.split("\n");

  for (const line of lines) {
    if (line.startsWith("data: ")) {
      const event = JSON.parse(line.slice(6));

      switch (event.type) {
        case "text":
          // Append to displayed text
          appendText(event.content);
          break;
        case "tool_call":
          // Show tool call indicator
          showToolCall(event.name, event.args);
          break;
        case "tool_result":
          // Show tool result
          showToolResult(event.call_id, event.result);
          break;
        case "complete":
          // Response finished
          break;
        case "error":
          // Handle error
          console.error(event.message);
          break;
      }
    }
  }
}

Error Responses

All error responses follow this format:

{
  "error": "Description of what went wrong"
}
Status CodeMeaning
400Bad request (missing or invalid parameters)
401Unauthorized (invalid or missing API key)
403Forbidden (API key does not authorize this app)
404Not found (session or resource does not exist)
500Internal server error

Next Steps

On this page