Creating and Using Threads

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.

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

1import requests
2
3BASE_URL = "https://alfa.boosted.ai/client"
4API_KEY = "YOUR_API_KEY_HERE"
5
6headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
7
8def get_all_threads() -> list[tuple[str, str]] | None:
9 """
10 Returns all threads with Alfa as a list of tuples: (name, thread ID)
11 """
12 url = f"{BASE_URL}/v2/thread/all"
13 response = requests.get(url, headers=headers)
14
15 if response.status_code == 200:
16 data = response.json()
17 return [(thread["thread_name"], thread["thread_id"]) for thread in data["threads"]]
18
19 else:
20 print(f"Error: {response.status_code}, {response.text}")
21 return None

Create new threads

1import requests
2
3BASE_URL = "https://alfa.boosted.ai/client"
4API_KEY = "YOUR_API_KEY_HERE"
5
6headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
7
8
9def create_thread(thread_name: str) -> str | None:
10 """Create a new thread with Alfa and return its ID."""
11 url = f"{BASE_URL}/v2/thread/new"
12
13 payload = {
14 "thread_name": thread_name
15 }
16
17 response = requests.post(url, headers=headers, json=payload)
18
19 if response.status_code == 200:
20 data = response.json()
21 thread_id = data["thread_id"]
22 print("Created new thread with ID: ", thread_id)
23 return thread_id
24 else:
25 print(f"Error: {response.status_code}, {response.text}")
26 return None
27
28new_thread_id = create_thread()

Get thread messages

1import requests
2
3BASE_URL = "https://alfa.boosted.ai/client"
4API_KEY = "YOUR_API_KEY_HERE"
5
6headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
7
8def get_thread_messages(thread_id: str):
9 """
10 Get all messages in a thread.
11 """
12 url = f"{BASE_URL}/v2/thread/history/{thread_id}"
13
14 response = requests.get(url, headers=headers)
15
16 if response.status_code == 200:
17 data = response.json()
18 total_messages = data["total_message_count"]
19 messages = sorted(data["messages"], key=lambda message: message["message_time"])
20 print(f"Got {total_messages} total messages")
21 print(messages)
22 else:
23 print(f"Error: {response.status_code}, {response.text}")
24

Chatting in threads

1import requests
2
3BASE_URL = "https://alfa.boosted.ai/client"
4API_KEY = "YOUR_API_KEY_HERE"
5
6headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
7
8def chat_in_thread(thread_id: str, message: str):
9 """
10 Send a message in the chat thread.
11 """
12 url = f"{BASE_URL}/v2/thread/chat"
13
14 payload = {"thread_id": thread_id, "message": message}
15
16 response = requests.post(url, headers=headers, json=payload)
17
18 if response.status_code == 200:
19 data = response.json()
20 success = data["success"]
21 if success:
22 print("Message sent successfully")
23 return
24
25 print(f"Error: {response.status_code}, {response.text}")
26

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