Skip to main content
GET
/
session
/
{session_id}
/
messages
Python
from acontext import AcontextClient

client = AcontextClient(api_key='sk_project_token')

# Get messages from session
messages = client.sessions.get_messages(
    session_id='session-uuid',
    limit=50,
    format='acontext',
    time_desc=True
)
for message in messages.items:
    print(f"{message.role}: {message.parts}")
{
  "code": 123,
  "error": "<string>",
  "msg": "<string>",
  "data": {
    "edit_at_message_id": "<string>",
    "has_more": true,
    "ids": [
      "<string>"
    ],
    "items": {},
    "metas": [
      {}
    ],
    "next_cursor": "<string>",
    "public_urls": {},
    "this_time_tokens": 123
  }
}

Authorizations

Authorization
string
header
required

Project Bearer token (e.g., "Bearer sk-ac-xxxx")

Path Parameters

session_id
string<uuid>
required

Session ID

Query Parameters

limit
integer

Limit of messages to return. Max 200. If limit is 0 or not provided, all messages will be returned.

WARNING! Use limit only for read-only/display purposes (pagination, viewing). Do NOT use limit to truncate messages before sending to LLM as it may cause tool-call and tool-result unpairing issues. Instead, use the token_limit edit strategy in edit_strategies parameter to safely manage message context size.

cursor
string

Cursor for pagination. Use the cursor from the previous response to get the next page.

with_asset_public_url
boolean

Whether to return asset public url, default is true

format
enum<string>

Format to convert messages to: acontext (original), openai (default), anthropic, gemini.

Available options:
acontext,
openai,
anthropic,
gemini
time_desc
boolean

Order by created_at descending if true, ascending if false (default false)

edit_strategies
string

JSON array of edit strategies to apply before format conversion

pin_editing_strategies_at_message
string

Message ID to pin editing strategies at. When provided, strategies are only applied to messages up to and including this message ID, keeping subsequent messages unchanged. This helps maintain prompt cache stability by preserving a stable prefix. The response will include edit_at_message_id indicating where strategies were applied.

Response

200 - application/json

OK

code
integer
error
string
msg
string
data
object