Individual Chats
Here you can learn the basics of how to work with chats using Python scripts.
What Is a Chat
Section titled “What Is a Chat”A Chat in the Quantly API is an interactive session where you can submit queries or inputs, optionally attaching relevant data sources like company information, documents, or files. The API processes these inputs using AI agents and returns detailed responses.
How to Start a Chat
Section titled “How to Start a Chat”You can start a chat with Quantly without providing additional context. In this case, Quantly uses the query context to identify relevant information—for example, if the query mentions “Apple,” it will automatically search for the relevant company ID and associated documents before responding.
Here’s how to create a chat with just an input:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
data = { "Input": "Give me the key points from latest Apple earnings call"}
response = requests.post(f"{base_url}/v1/chats", headers=headers, json=data)
if response.status_code == 200: chat_data = response.json() print(chat_data)else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
In response to any successful chat creation, you receive an ID for the created chat. You can obtain it like this:
chat_id = chat_data['data']['id']There is another way of getting chat IDs—the chats/search endpoint, which can give you the ID of any chat that you have. For more information about it, see the API Reference.
Let’s look at how you can use this ID to get the contents of the chat.
How to Get a Chat
Section titled “How to Get a Chat”When you have an ID of some existing chat, here’s how you can get all the information about it:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
chat_id = "your_chat_id"
response = requests.get(f"{base_url}/v1/chats/{chat_id}", headers=headers)
if response.status_code == 200: chat_data = response.json() print(chat_data)else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
This endpoint gives you a lot of information about the chat, but if you need only the content of the latest message, here’s how you can get it:
last_message_content = chat_data['data']['messages'][-1]['data']['content']Hint: you can check
chat_data['data'].get('finishedAt') != Noneto know if the chat has finished processing.
How to Send a Follow-Up Message to the Chat
Section titled “How to Send a Follow-Up Message to the Chat”If you have the ID of a finished chat in which you want to continue asking questions, you can do so like this:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
chat_id = "your_chat_id"
data = { "Input": "Let's also add Apple's latest 8-K to the analysis."}
response = requests.post(f"{base_url}/v1/chats/{chat_id}/input", headers=headers, json=data)
if response.status_code == 200: chat_data = response.json() print(chat_data)else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Then you can use the method described in the previous section to monitor chat processing.
How to Use Additional Context
Section titled “How to Use Additional Context”To specify what exactly Quantly should analyze, you need to know how to uniquely identify each item.
Find Company IDs
Section titled “Find Company IDs”If you want Quantly to research a specific company - you’ll need its ID. Here’s how you can find it:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
params = { "Input": "Apple" # Can also use ticker symbol, e.g., "AAPL"}
response = requests.get(f"{base_url}/v1/companies/search", headers=headers, params=params)
if response.status_code == 200: companies = response.json()["data"] if companies: company_id = companies[0]["id"] company_name = companies[0]["name"] print(f"Found {company_name} with ID: {company_id}") else: print("No companies found matching the search criteria.")else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Note: Usually picking the first result should be fine, but sometimes what you searched for can appear lower in the list.
Find Company Document IDs
Section titled “Find Company Document IDs”If you know the ID of the company that you want to research, and want Quantly to focus on some specific document of that company, here’s how you can find a list of company documents to pick an ID from:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
company_id = 24937 # Apple's ID
params = { "Type": "Filing", # Can also be "Transcript", or not specified for all types "YearStart": 2023, "YearEnd": 2025, "Offset": 0, "Limit": 50}
response = requests.get(f"{base_url}/v1/companies/{company_id}/documents/search", headers=headers, params=params)
if response.status_code == 200: documents = response.json()["data"] if documents: for doc in documents: print(f"ID: {doc['id']}, Type: {doc['type']}, Title: {doc['title']}") else: print("No documents found matching the search criteria.")else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Note: all parameters in this example are optional, omit them to get all documents for the company, but don’t forget that you can control the pagination with “Limit” and “Offset”.
If you don’t have a certain company in mind and just want the latest documents, or if you want to get documents for multiple companies at once, you may find Search For Filings and Search For Transcripts endpoints useful.
Upload and Use Your Own Files
Section titled “Upload and Use Your Own Files”If you want Quantly to use your own files during the analysis, you need to upload them into the system first to get the IDs that you’ll be able to use later. Here’s how you can do it:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
files = [ ("File", ("your_file_name.pdf", open("path_to_your_file.pdf", "rb"), "application/pdf"))]
response = requests.post(f"{base_url}/v1/documents", headers=headers, files=files)
if response.status_code == 200: document = response.json() document_id = document["data"]["id"] print(f"Document uploaded successfully. Document ID: {document_id}")else: print(f"Error: {response.status_code}\n{response.content}")You can find detailed documentation for this endpoint here.
Start a Chat with Additional Context
Section titled “Start a Chat with Additional Context”When you have all the IDs that you need, you can specify them when starting the chat to make sure that Quantly focuses on exactly what you want to research:
import requests
api_key = "your_api_key_here"headers = {"Authorization": f"Bearer {api_key}"}base_url = "https://api-v2.quantly-ai.com"
data = { "Input": "Which company performed better based on these documents?", "CompanyIds": [24937, 29096], "FilingIds": ["9c57166e-8fa2-43e4-9502-712f8bf39bd3", "a578c184-a007-4c9f-bbcb-8a2cfaf9c4de"], "TranscriptIds": [3434465, 3424905], "SlideDeckIds": [12345, 67890], "UserDocumentIds": ["0197adbc-e34c-759b-8f18-289f7159aaf4", "0197adbc-e34d-7028-846f-79087dc77e7e"]}
response = requests.post(f"{base_url}/v1/chats", headers=headers, json=data)
if response.status_code == 200: chat_data = response.json() print(chat_data)else: print(f"Error: {response.status_code}\n{response.content}")Endpoint used here is the same as in “How to Start a Chat” section.
You can also add additional context in the same way when sending a follow-up message to the chat.
Check out the Reference if you need more information about any of these or many other endpoints that we have.