> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.alfa.boosted.ai/alfa/guides/chatting-in-threads/creating-and-using-threads/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.alfa.boosted.ai/_mcp/server. # Creating and Using Threads > Learn how to use chat threads to interact with Alfa. Threads are the best way to chat with Alfa to get fast answers. Alfa can perform data lookups across both quantitative and qualitative sources to provide an answer. > **Note** > > When chatting in threads, Alfa runs in "fast mode". This means it may not search sources as thoroughly as when using a workplan. If Alfa seems to be missing context or struggling to find what you need, try switching to a workplan for a more comprehensive search. ### Get all threads ```python import requests BASE_URL = "https://alfa.boosted.ai/client" API_KEY = "YOUR_API_KEY_HERE" headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} def get_all_threads() -> list[tuple[str, str]] | None: """ Returns all threads with Alfa as a list of tuples: (name, thread ID) """ url = f"{BASE_URL}/v2/thread/all" response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() return [(thread["thread_name"], thread["thread_id"]) for thread in data["threads"]] else: print(f"Error: {response.status_code}, {response.text}") return None ``` ### Create new threads ```python import requests BASE_URL = "https://alfa.boosted.ai/client" API_KEY = "YOUR_API_KEY_HERE" headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} def create_thread(thread_name: str) -> str | None: """Create a new thread with Alfa and return its ID.""" url = f"{BASE_URL}/v2/thread/new" payload = { "thread_name": thread_name } response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() thread_id = data["thread_id"] print("Created new thread with ID: ", thread_id) return thread_id else: print(f"Error: {response.status_code}, {response.text}") return None new_thread_id = create_thread() ``` ### Get thread messages ```python import requests BASE_URL = "https://alfa.boosted.ai/client" API_KEY = "YOUR_API_KEY_HERE" headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} def get_thread_messages(thread_id: str): """ Get all messages in a thread. """ url = f"{BASE_URL}/v2/thread/history/{thread_id}" response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() total_messages = data["total_message_count"] messages = sorted(data["messages"], key=lambda message: message["message_time"]) print(f"Got {total_messages} total messages") print(messages) else: print(f"Error: {response.status_code}, {response.text}") ``` ### Chatting in threads ```python import requests BASE_URL = "https://alfa.boosted.ai/client" API_KEY = "YOUR_API_KEY_HERE" headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} def chat_in_thread(thread_id: str, message: str): """ Send a message in the chat thread. """ url = f"{BASE_URL}/v2/thread/chat" payload = {"thread_id": thread_id, "message": message} response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() success = data["success"] if success: print("Message sent successfully") return print(f"Error: {response.status_code}, {response.text}") ``` Note that a second API call must be made to fetch chat contents after a message is successfully sent. (See `get_thread_messages` above.) #### Choosing sources Alfa will try to respect the user's preferences for data sources. For example: > Look for any new business initiatives for Apple. Use only filings and earnings reports. By default, Alfa will use all data sources available to it. These include: * Web search * News * Earnings documents (call transcripts, reports, etc.) * Regulatory filings > Learn how to use chat threads to interact with Alfa.