Skip to main content

Overview

Chat sessions enable persistent conversation history tied to wallet addresses. Each session stores messages with metadata including payment transactions and AI-generated images.
All chat endpoints require Supabase to be configured. If unavailable, endpoints return 503 Service Unavailable.

Get All Sessions

curl -X GET "https://api.example.com/chat/sessions?wallet=0x1234..." 
Query Parameters
wallet
string
required
Wallet address to fetch sessions for
{
  "success": true,
  "sessions": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "wallet_address": "0x1234...",
      "title": "DeFi Yield Analysis",
      "created_at": "2026-03-01T10:00:00.000Z",
      "updated_at": "2026-03-03T10:30:00.000Z",
      "message_count": 24
    },
    {
      "id": "660e8400-e29b-41d4-a716-446655440001",
      "wallet_address": "0x1234...",
      "title": "NFT Floor Prices",
      "created_at": "2026-02-28T15:00:00.000Z",
      "updated_at": "2026-03-02T09:15:00.000Z",
      "message_count": 8
    }
  ]
}
Response Fields
success
boolean
required
Whether the request succeeded
sessions
array
required
Array of chat session objects

Create Session

curl -X POST https://api.example.com/chat/sessions \
  -H "Content-Type: application/json" \
  -d '{
    "walletAddress": "0x1234...",
    "title": "Token Price Analysis"
  }'
Request Body
walletAddress
string
required
Wallet address that owns this session
title
string
Optional session title (defaults to timestamp-based title)
{
  "success": true,
  "session": {
    "id": "770e8400-e29b-41d4-a716-446655440002",
    "wallet_address": "0x1234...",
    "title": "Token Price Analysis",
    "created_at": "2026-03-03T10:45:00.000Z",
    "updated_at": "2026-03-03T10:45:00.000Z"
  }
}

Delete Session

curl -X DELETE "https://api.example.com/chat/sessions/550e8400-e29b-41d4-a716-446655440000?wallet=0x1234..."
Path Parameters
sessionId
string
required
UUID of the session to delete
Query Parameters
wallet
string
required
Wallet address (must match session owner for authorization)
{
  "success": true
}
Deleting a session also deletes all messages in that session. This action cannot be undone.

Get Messages

curl -X GET https://api.example.com/chat/sessions/550e8400-e29b-41d4-a716-446655440000/messages
Path Parameters
sessionId
string
required
UUID of the session
{
  "success": true,
  "messages": [
    {
      "id": "msg-1234567890",
      "session_id": "550e8400-e29b-41d4-a716-446655440000",
      "content": "What's the price of BTC?",
      "is_user": true,
      "escrow_id": null,
      "tx_hash": "0xabc...",
      "image_preview": null,
      "created_at": "2026-03-03T10:30:00.000Z"
    },
    {
      "id": "msg-1234567891",
      "session_id": "550e8400-e29b-41d4-a716-446655440000",
      "content": "Bitcoin is currently trading at $65,000 USD.",
      "is_user": false,
      "escrow_id": "123",
      "tx_hash": "0xdef...",
      "image_preview": null,
      "created_at": "2026-03-03T10:30:05.000Z"
    }
  ]
}
Response Fields
success
boolean
required
Whether the request succeeded
messages
array
required
Array of message objects, ordered by creation time

Save Message

curl -X POST https://api.example.com/chat/sessions/550e8400-e29b-41d4-a716-446655440000/messages \
  -H "Content-Type: application/json" \
  -d '{
    "id": "msg-1234567892",
    "content": "Show me yield opportunities on Arbitrum",
    "is_user": true,
    "tx_hash": "0xabc123...",
    "image_preview": null
  }'
Path Parameters
sessionId
string
required
UUID of the session
Request Body
id
string
required
Unique message ID (client-generated)
content
string
required
Message text content
is_user
boolean
required
True if user message, false if AI response
escrow_id
string
Associated escrow ID (for AI responses with payments)
tx_hash
string
Payment transaction hash
image_preview
string
Base64-encoded image data URL (for image-based queries)
{
  "success": true,
  "message": {
    "id": "msg-1234567892",
    "session_id": "550e8400-e29b-41d4-a716-446655440000",
    "content": "Show me yield opportunities on Arbitrum",
    "is_user": true,
    "escrow_id": null,
    "tx_hash": "0xabc123...",
    "image_preview": null,
    "created_at": "2026-03-03T10:50:00.000Z"
  }
}

Clear Messages

curl -X DELETE https://api.example.com/chat/sessions/550e8400-e29b-41d4-a716-446655440000/messages
Path Parameters
sessionId
string
required
UUID of the session
{
  "success": true
}
Deletes all messages in the session, but keeps the session itself.

Error Responses

{
  "success": false,
  "error": "Wallet address required"
}
{
  "success": false,
  "error": "Failed to create session"
}
{
  "success": false,
  "error": "Supabase unavailable. Check SUPABASE_URL/SUPABASE_ANON_KEY and restart backend."
}

Integration Example

// Create a new chat session
const createSession = async (walletAddress: string) => {
  const response = await fetch('https://api.example.com/chat/sessions', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      walletAddress,
      title: 'New Conversation',
    }),
  });
  const { session } = await response.json();
  return session.id;
};

// Save user message
const saveUserMessage = async (sessionId: string, content: string, txHash: string) => {
  await fetch(`https://api.example.com/chat/sessions/${sessionId}/messages`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      id: `msg-${Date.now()}`,
      content,
      is_user: true,
      tx_hash: txHash,
    }),
  });
};

// Save AI response
const saveAIResponse = async (sessionId: string, content: string, escrowId: string) => {
  await fetch(`https://api.example.com/chat/sessions/${sessionId}/messages`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      id: `msg-${Date.now()}`,
      content,
      is_user: false,
      escrow_id: escrowId,
    }),
  });
};

// Load conversation history
const loadHistory = async (sessionId: string) => {
  const response = await fetch(`https://api.example.com/chat/sessions/${sessionId}/messages`);
  const { messages } = await response.json();
  return messages;
};

Database Schema

Chat sessions are stored in Supabase with the following structure: chat_sessions table:
  • id (uuid, primary key)
  • wallet_address (text)
  • title (text, nullable)
  • created_at (timestamp)
  • updated_at (timestamp)
messages table:
  • id (text, primary key)
  • session_id (uuid, foreign key)
  • content (text)
  • is_user (boolean)
  • escrow_id (text, nullable)
  • tx_hash (text, nullable)
  • image_preview (text, nullable)
  • created_at (timestamp)
Messages are automatically ordered by created_at when fetched.

Build docs developers (and LLMs) love