Threads
Learn how to orchestrate conversational threads with the Alfa (Preview) API.
This API is currently in Preview.
Overview
Threads keep every Alfa API exchange stateful so you can execute long-running research, pause work, and resume with full context. Each thread stores metadata, message history, task progress, and structured artifacts generated during analysis.
- Use
POST /v2/threadsto create a new thread andGET /v2/threadsto discover existing ones. - Send instructions with
POST /v2/threads/{thread_id}/messagesand stream events using gRPC or SSE streaming. - See chat history and structured data table outputs with
GET /v2/threads/{thread_id}/messagesandGET /v2/threads/{thread_id}/artifacts/{artifact_id}respectively.
Review the API reference after finishing this guide to inspect every request and response schema.
Thread lifecycle
Send a message and stream updates
Submit the user prompt with POST /v2/threads/{thread_id}/messages. Use gRPC or SSE streaming to receive incremental reasoning, artifacts, and completion events in real time.
Create and manage threads
Threads are lightweight resources. You can list, rename, or delete them without touching other workloads.
Deleting a thread removes all artifacts and history permanently. Be careful when issuing DELETE /v2/threads/{thread_id}.
Send messages
POST /v2/threads/{thread_id}/messages validates the caller has access to the thread, queues the task, and returns immediately. To receive real-time updates, use gRPC or SSE streaming.
To stream thread events in real time, see the streaming guide for both gRPC and SSE options. If a stream closes before completion, call GET /v2/threads/{thread_id}/progress to check status.
Retrieve history and artifacts
Use the history endpoint to build up the log of chat messages sent over the course of a conversation, and the artifacts endpoint to retrieve structured data output.
Artifacts are structured data outputs (such as tables, charts, or JSON objects) generated during thread execution. Unlike plain text responses, artifacts contain formatted data that can be retrieved and rendered separately using their unique artifact_id.
Tie artifact IDs to the message_id returned by GET /v2/threads/{thread_id}/messages so you can render both the prose answer and the structured data.
Upload user files to a thread
Attach supporting documents directly to a thread so the model can cite them during follow-up prompts. The endpoint expects multipart form data and associates the uploaded blob with the specified thread.
Store the returned file_id next to the thread metadata so later POST /v2/threads/{thread_id}/messages calls can reference the uploaded evidence in user prompts.
Cancel a running task
Use the cancellation endpoint to stop the currently processing message whenever a user changes their mind. The API records a “User cancelled” entry in the thread so downstream reviewers can see why work halted.
