# Get thread messages div strong 🔨 In Development — This section is still being developed and may change. Retrieve all messages from a specific thread with pagination support. Retrieve all messages from a specific thread with pagination support. Returns messages in chronological order with full content and metadata. #### Assistant Message Enhancements For messages where `role` is `assistant`, the response may include `toolCalls` and `iterations` arrays, providing detailed insight into the model's execution process. - **`toolCalls`**: An array of objects detailing any tools the model invoked to generate the response. Each object includes the function name, arguments, and the result returned by the tool. - **`iterations`**: An array of objects that captures the model's reasoning or "thought process" steps. This is useful for debugging and understanding how the model arrived at its final answer. These fields will only be present if the assistant used tools or went through reasoning steps to generate the message. #### Path Parameters **`thread_id`** string required The unique identifier of the thread to retrieve messages from. #### Query Parameters **`limit`** integer optional · Defaults to `20` Number of messages to return. Must be between 1 and 100. **`order`** string optional · Defaults to `asc` Sort order for messages. Available values: `asc` (oldest first), `desc` (newest first). **`after`** string optional Cursor for pagination. Returns messages created after the specified message ID. **`before`** string optional Cursor for pagination. Returns messages created before the specified message ID. Basic ```bash curl "https://api.freddy.aitronos.com/v1/threads/thread_abc123/messages?limit=20" \ -H "Authorization: Bearer $FREDDY_API_KEY" ``` ```python import requests response = requests.get( "https://api.freddy.aitronos.com/v1/threads/thread_abc123/messages", headers={"Authorization": f"Bearer {api_key}"}, params={"limit": 20} ) messages = response.json() print(f"Found {len(messages['data'])} messages") ``` ```javascript const response = await fetch('https://api.freddy.aitronos.com/v1/threads/thread_abc123/messages?limit=20', { headers: { 'Authorization': `Bearer ${apiKey}` } }); const messages = await response.json(); console.log(`Found ${messages.data.length} messages`); ``` Pagination ```bash # First page curl "https://api.freddy.aitronos.com/v1/threads/thread_abc123/messages?limit=10" \ -H "Authorization: Bearer $FREDDY_API_KEY" # Next page curl "https://api.freddy.aitronos.com/v1/threads/thread_abc123/messages?limit=10&after=msg_abc123" \ -H "Authorization: Bearer $FREDDY_API_KEY" ``` ```python import requests def get_messages_page(thread_id, limit=10, after=None): params = {"limit": limit} if after: params["after"] = after response = requests.get( f"https://api.freddy.aitronos.com/v1/threads/{thread_id}/messages", headers={"Authorization": f"Bearer {api_key}"}, params=params ) return response.json() # Get first page first_page = get_messages_page("thread_abc123", 10) print(f"First page: {len(first_page['data'])} messages") # Get next page if first_page['has_more']: next_page = get_messages_page("thread_abc123", 10, first_page['last_id']) print(f"Next page: {len(next_page['data'])} messages") ``` ```javascript async function getMessagesPage(threadId, limit = 10, after = null) { const params = new URLSearchParams({ limit: limit.toString() }); if (after) params.append('after', after); const response = await fetch(`https://api.freddy.aitronos.com/v1/threads/${threadId}/messages?${params}`, { headers: { 'Authorization': `Bearer ${apiKey}` } }); return await response.json(); } // Get first page const firstPage = await getMessagesPage("thread_abc123", 10); console.log(`First page: ${firstPage.data.length} messages`); // Get next page if (firstPage.has_more) { const nextPage = await getMessagesPage("thread_abc123", 10, firstPage.last_id); console.log(`Next page: ${nextPage.data.length} messages`); } ``` ## Response 200 OK ```json { "object": "list", "data": [ { "id": "msg_abc123", "object": "thread.message", "createdAt": 1741476542, "threadId": "thread_abc123", "role": "user", "content": [ { "type": "text", "text": "Hello, I need help with billing" } ], "metadata": {} }, { "id": "msg_xyz789", "object": "thread.message", "createdAt": 1741476600, "threadId": "thread_abc123", "role": "assistant", "content": [ { "type": "text", "text": "I have retrieved the billing information for you." } ], "toolCalls": [ { "id": "call_123", "type": "function", "function": { "name": "get_billing_info", "arguments": "{\\"user_id\\":\\"user_abc123\\"}" }, "result": "{\\"status\\":\\"success\\",\\"billing_amount\\":120.50}" } ], "iterations": [ { "type": "reasoning", "content": "The user is asking for billing information. I will use the get_billing_info tool." } ], "metadata": {} } ], "firstId": "msg_abc123", "lastId": "msg_xyz789", "hasMore": false } ``` Errors ```json 404 Not Found { "error": { "message": "Thread not found or access denied", "type": "not_found_error", "code": "thread_not_found" } } ``` ```json 401 Unauthorized { "error": { "message": "Authentication required", "type": "authentication_error", "code": "missing_authentication" } } ``` ```json 403 Forbidden { "error": { "message": "Access denied to thread", "type": "permission_error", "code": "insufficient_permissions" } } ``` ## Related Resources - [Threads Overview](/docs/documentation/core-concepts/threads-overview) - [Retrieve Thread](/docs/api-reference/threads/retrieve) - [Update Message](/docs/api-reference/threads/update-message) - [Delete Message](/docs/api-reference/threads/delete-message) - [Thread Context Modes](/docs/documentation/core-concepts/thread-context-modes)