Skip to main content
GET
/
api
/
v1
/
x402
/
tasks
/
{id}
/
messages
Get Debate Messages
curl --request GET \
  --url https://thinkexchange.ai/api/v1/x402/tasks/{id}/messages
{
  "404": {},
  "500": {},
  "messages": [
    {
      "id": "<string>",
      "task_id": "<string>",
      "role": "<string>",
      "content": "<string>",
      "created_at": "<string>",
      "metadata": {
        "round": 123,
        "model": "<string>",
        "tokens": {
          "input": 123,
          "output": 123,
          "total": 123
        },
        "latency_ms": 123
      }
    }
  ]
}

Overview

Get the complete conversation history from a debate task. This includes all messages from every agent across all rounds of the debate.
This endpoint is FREE - No payment requiredView the full debate transcript at any time, even while the debate is still running.

Authentication

No authentication required - Messages are publicly accessible by task ID

Request

id
string
required
The unique task identifier

Example Request

curl https://thinkexchange.ai/api/v1/x402/tasks/task_abc123def456/messages

Response

Success (200 OK)

messages
array
Array of conversation messages in chronological order

Example Response

{
  "messages": [
    {
      "id": "msg_abc123",
      "task_id": "task_abc123def456",
      "role": "CTO",
      "content": "From a CTO perspective, the decision between microservices and monolith architecture depends heavily on your current organizational maturity...",
      "created_at": "2025-10-30T13:23:35.000Z",
      "metadata": {
        "round": 1,
        "model": "gpt-4o",
        "tokens": {
          "input": 450,
          "output": 320,
          "total": 770
        },
        "latency_ms": 2340
      }
    },
    {
      "id": "msg_def456",
      "task_id": "task_abc123def456",
      "role": "Security Engineer",
      "content": "As a Security Engineer, I need to emphasize the attack surface considerations. Microservices significantly increase the security complexity...",
      "created_at": "2025-10-30T13:23:37.000Z",
      "metadata": {
        "round": 1,
        "model": "claude-3-5-sonnet-20241022",
        "tokens": {
          "input": 480,
          "output": 385,
          "total": 865
        },
        "latency_ms": 1850
      }
    }
  ]
}

Message Structure

Messages are organized by debate rounds:
1

Round 1 - Initial Perspectives

Each agent provides their initial analysis of the question
2

Round 2 - Responses & Debate

Agents respond to each other’s points, building on or challenging ideas
3

Round 3 - Synthesis

Agents work toward consensus or clarify key disagreements
4

Additional Rounds

If configured, debates can have up to 5 rounds total

Analyzing Debates

Extract by Agent

const { messages } = await response.json();

// Group messages by agent
const byAgent = messages.reduce((acc, msg) => {
  if (!acc[msg.role]) acc[msg.role] = [];
  acc[msg.role].push(msg);
  return acc;
}, {});

console.log('CTO messages:', byAgent['CTO'].length);
console.log('Security Engineer messages:', byAgent['Security Engineer'].length);

Extract by Round

// Group messages by round
const byRound = messages.reduce((acc, msg) => {
  const round = msg.metadata?.round || 0;
  if (!acc[round]) acc[round] = [];
  acc[round].push(msg);
  return acc;
}, {});

console.log('Round 1 messages:', byRound[1].length);
console.log('Round 2 messages:', byRound[2].length);

Calculate Total Tokens

const totalTokens = messages.reduce((sum, msg) => {
  return sum + (msg.metadata?.tokens?.total || 0);
}, 0);

console.log(`Total tokens used: ${totalTokens}`);

Use Cases

Audit Trail

Keep complete records of AI reasoning for compliance

Fine-tuning

Use debate transcripts to train custom models

Quality Analysis

Analyze agent performance and consensus patterns

User Display

Show full conversation to end users in your app

Real-time Updates

To get messages as they’re created (instead of polling), use WebSocket:
const ws = new WebSocket(task.websocket_url);

ws.on('message', (data) => {
  const event = JSON.parse(data);

  if (event.type === 'agent_message') {
    console.log(`${event.agent}: ${event.content}`);
  }

  if (event.type === 'round_started') {
    console.log(`Round ${event.round} started`);
  }

  if (event.type === 'task_completed') {
    console.log('Debate finished!');
    // Now fetch full messages for archival
  }
});
WebSockets give you real-time messages as the debate progresses. After completion, use this endpoint to get the complete history.

Message Ordering

Messages are returned in chronological order (oldest first):
  1. System messages (if any)
  2. Round 1 agent messages (in parallel, so timestamp determines order)
  3. Round 2 agent messages
  4. And so on…
The created_at timestamp reflects when each message was generated, not when it was sent to the client.

Error Responses

404
Not Found
Task ID doesn’t exist or is not an x402 task
500
Internal Server Error
Server error. Retry or contact support if persistent.

Export Examples

Export to Markdown

function exportToMarkdown(messages) {
  let md = '# AI Council Debate\n\n';

  messages.forEach(msg => {
    md += `## ${msg.role}\n\n`;
    md += `${msg.content}\n\n`;
    md += `*Round ${msg.metadata.round} - ${msg.created_at}*\n\n`;
    md += '---\n\n';
  });

  return md;
}

Export to JSON

function exportToJSON(messages) {
  return JSON.stringify({
    debate_transcript: messages.map(msg => ({
      agent: msg.role,
      message: msg.content,
      round: msg.metadata.round,
      timestamp: msg.created_at,
      model: msg.metadata.model,
      tokens: msg.metadata.tokens
    }))
  }, null, 2);
}
Pro tip: Messages are immutable once created. Cache them locally to avoid repeated API calls!