Skip to content

Execute

All execution endpoints accept X-API-Key: eak_... (or wak_...) and X-Workspace-Id: workspace:YOUR_ID.

Base URL: https://athena-dev-api.leanscale.com


Request Body

{
"message": "Summarise my last 7 days of activity",
"attachments": [
{
"filename": "notes.pdf",
"content_type": "application/pdf",
"storage_key": "attachments/user_abc/a1b2c3.pdf"
}
],
"variables": { "tone": "professional" },
"conversation_scope": "conversation:abc123",
"external_user_id": "firebase_uid_xyz",
"client_tools": [
{
"name": "query_transactions",
"description": "Query the user's local transaction ledger",
"parameters": {
"type": "object",
"properties": {
"start_date": { "type": "string", "format": "date" },
"end_date": { "type": "string", "format": "date" }
},
"required": ["start_date", "end_date"]
}
}
]
}
FieldRequiredDescription
messageConditionalUser input (1–65,536 chars). Required when the agent has requires_user_message: true.
attachmentsNoFile references via storage_key (max 10).
variablesNoInput variables for wizard agents. Capped at 16 KiB.
conversation_scopeNoConversation ID — enables message history injection and auto-persistence.
external_user_idNoYour user’s ID — enables per-user memory personalization.
client_toolsNoClient-fulfilled tool definitions. Max 32 per request.

Sync Execution

POST /agents/{agent_id}/execute
X-API-Key: eak_...
X-Workspace-Id: workspace:YOUR_ID

Blocks until the workflow completes. Response is a single JSON object.

{
"data": {
"execution_id": "execution:xyz",
"status": "completed",
"output": {
"text": "Here is your summary...",
"usage": { "input_tokens": 150, "output_tokens": 280, "total_tokens": 430 },
"cost_microdollars": 4200
},
"latency_ms": 2341
}
}

Status values: completed, awaiting_approval, waiting_for_external_event, awaiting_client_tool, failed.


Streaming Execution (SSE)

POST /agents/{agent_id}/execute/stream
X-API-Key: eak_...
X-Workspace-Id: workspace:YOUR_ID
Content-Type: application/json

Returns text/event-stream. Each event is data: <json>\n\n.

EventWhenAction
startFirst eventCapture execution_id for tracking
textEach LLM token chunkAppend to displayed text
reasoningThinking chunksShow thinking indicator
tool_callLLM invokes a server toolShow tool execution UI
tool_resultServer tool returns resultShow tool output
tool_call_awaiting_clientLLM invokes a client toolRun tool locally and POST result
node_start / node_completeWorkflow node lifecycleProgress indicators
media_gen_submittedImage/video gen startedShow generating indicator
media_gen_completeImage/video gen doneRender the generated media
heartbeatEvery 15 s during gen waitKeep-alive — ignore in UI
finalWorkflow completeExtract final usage and cost. Stream ends.
errorExecution failedShow error. Credits are auto-refunded.

Batch Execution

POST /agents/{agent_id}/execute/batch
X-API-Key: eak_...
X-Workspace-Id: workspace:YOUR_ID
Content-Type: application/json
{
"items": [
{ "key": "item-1", "message": "Summarize this article: ..." },
{ "key": "item-2", "message": "Translate to French: ..." }
]
}

Returns SSE: batch_startedbatch_progress (per item) → batch_completed.


Idempotency

Prevent duplicate executions (and double credit charges) with an Idempotency-Key header:

POST /agents/{agent_id}/execute
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000
ScenarioResult
First request with keyProcessed normally
Same key within 24 hours409 Conflict — no execution, no charge
Same key after 24 hoursProcessed normally — key expired

Credit Preview

Estimate the credit cost before executing:

POST /agents/{agent_id}/preview-credits
X-API-Key: eak_...
{ "inputs": { "tone": "professional", "length": "long" } }

Returns the credit calculation with base cost and rule breakdown. No execution is created.


Client-Fulfilled Tools

Client tools let the LLM invoke functions that run on the client device. The AI node must have accepts_client_tools: true.

Flow:

  1. Your app sends client_tools in the execute request.
  2. If the LLM calls a client tool, execution suspends — status becomes awaiting_client_tool.
  3. SSE emits tool_call_awaiting_client.
  4. Your app runs the tool locally and POSTs the result:
POST /executions/{execution_id}/tool-result
X-API-Key: eak_...
{
"tool_call_id": "tc_abc123",
"outcome": "success",
"result": { "transactions": [], "total": 5.50 }
}
  1. The last fulfilled call resumes execution automatically.

Add Accept: text/event-stream to the tool-result POST to receive the resumed execution as an SSE stream.

Tool name rules: must match ^[a-z][a-z0-9_]{0,63}$ and must not collide with server-side tools on the agent.


File Attachments

Step 1: Upload the file

POST /attachments/upload
X-API-Key: eak_...
Content-Type: multipart/form-data
file: <binary data>

Response includes a storage_key string.

Step 2: Reference in execute request

Pass storage_key in the attachments array.

ConstraintValue
Max attachments per request10
Max file size50 MiB
Supported image typesimage/jpeg, image/png, image/gif, image/webp
Supported document typesapplication/pdf, text/plain, text/csv, text/markdown

Conversations

Use conversations to maintain message history across turns.

Create or resume a conversation:

POST /my/conversations
X-API-Key: eak_...
{ "agent_id": "agent:0bve9rxqh0hm7t5bq24j" }

Returns 201 (new) or 200 (existing active conversation).

Execute with conversation history: pass conversation_scope in your execution request body. This injects prior messages as context and auto-persists the new exchange.

Start a fresh chat: archive the current conversation before the next POST /my/conversations:

POST /my/conversations/{conversation_id}/archive

Message roles:

roleAuthorReplayed to LLM?
userEnd userYes
assistantAgent (LLM output)Yes
toolTool resultYes
systemAthena platform (failures, handoffs)No

Message feedback:

POST /my/conversations/{cid}/messages/{mid}/feedback
{ "value": 1 }

1 = thumbs up, -1 = thumbs down.


Structured Output

When an agent’s AI node has output_schema configured, responses include parsed_output alongside text:

{
"data": {
"output": {
"text": "{\"type\":\"card\",\"amount\":\"$2,450\"}",
"parsed_output": { "type": "card", "amount": "$2,450" }
}
}
}

Use parsed_output when present. Fall back to parsing text manually if parsed_output is null.


Response Headers

Every authenticated response includes:

HeaderValue
X-Credits-RemainingCurrent credit balance (eak_ + customer only)
X-App-VersionThe workspace’s current published AppVersion ID
X-Workspace-IdEcho of the workspace ID

Cache X-App-Version locally. When it changes, refetch CMS data.


  • Authentication — key types, scopes, token exchange
  • Webhooks — receive events from Fal.ai and RevenueCat
  • Errors — error shapes and retry guidance
  • Workflows — HumanGate resume and MediaGeneration events