Skip to main content

Document Search API

Search for specific documents across AlphaSense's database with keyword, date, and company filters. Returns document-level results with text snippets.

GraphQL Query

query SearchDocuments(
$filter: SearchFilter!
$limit: Int!
$sorting: SearchSorting!
$cursor: String
) {
search(filter: $filter, limit: $limit, sorting: $sorting, cursor: $cursor) {
cursor
totalCount
documents {
id
title
releasedAt
snippets(limit: 20) {
statements {
text
}
}
}
}
}

Filter Parameters

ParameterTypeDescription
filter.keyword.queryStringSearch keywords
filter.date.presetEnumLAST_24_HOURS, LAST_7_DAYS, LAST_30_DAYS, LAST_90_DAYS, LAST_1_YEAR, LAST_2_YEARS
filter.companies.ids[String]Company ticker symbols (e.g., ["AAPL"])
filter.types.ids[String]Source type IDs (e.g., ["21000"] for Expert Calls)
limitIntMax documents to return
sorting.fieldEnumDATE
sorting.directionEnumASC, DESC
cursorStringPagination cursor from previous response

Code Examples

import os
import requests

API_KEY = os.environ["ALPHASENSE_API_KEY"]
CLIENT_ID = os.environ["ALPHASENSE_CLIENT_ID"]
CLIENT_SECRET = os.environ["ALPHASENSE_CLIENT_SECRET"]
EMAIL = os.environ["ALPHASENSE_EMAIL"]
PASSWORD = os.environ["ALPHASENSE_PASSWORD"]

# Authenticate to obtain a bearer token (see Authentication guide)
auth_response = requests.post(
"https://api.alpha-sense.com/auth",
headers={
"x-api-key": API_KEY,
"Content-Type": "application/x-www-form-urlencoded",
},
data={
"grant_type": "password",
"username": EMAIL,
"password": PASSWORD,
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
},
)
auth_response.raise_for_status()
access_token = auth_response.json()["access_token"]

url = "https://api.alpha-sense.com/gql"

headers = {
"x-api-key": API_KEY,
"clientid": CLIENT_ID,
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}

query = """
query SearchDocuments($filter: SearchFilter!, $limit: Int!, $sorting: SearchSorting!, $cursor: String) {
search(filter: $filter, limit: $limit, sorting: $sorting, cursor: $cursor) {
cursor
totalCount
documents {
id
title
releasedAt
snippets(limit: 20) {
statements {
text
}
}
}
}
}
"""

variables = {
"filter": {
"keyword": {
"query": "AI strategy"
},
"date": {
"preset": "LAST_30_DAYS"
}
},
"limit": 20,
"sorting": {
"field": "DATE",
"direction": "DESC"
}
}

response = requests.post(url, headers=headers, json={"query": query, "variables": variables})
data = response.json()

# Handle the response
results = data["data"]["search"]
print(f"Total documents found: {results['totalCount']}")

for doc in results["documents"]:
print(f"\n--- {doc['title']} (Released: {doc['releasedAt']}) ---")
for snippet in doc["snippets"]:
for statement in snippet["statements"]:
print(f" {statement['text']}")

# Store cursor for pagination
next_cursor = results["cursor"]

Response Handling

A successful response returns a JSON object with the following structure:

{
"data": {
"search": {
"cursor": "eyJsYXN0SWQiOiIxMjM0NTY3ODkwIn0=",
"totalCount": 342,
"documents": [
{
"id": "doc-abc-123",
"title": "Q4 Earnings Call Transcript - AI Strategy Overview",
"releasedAt": "2025-11-15T14:30:00Z",
"snippets": [
{
"statements": [
{
"text": "Our AI strategy focuses on three core pillars: automation, intelligence augmentation, and predictive analytics..."
}
]
}
]
}
]
}
}
}

Check for errors in the response before processing results:

data = response.json()

if "errors" in data:
for error in data["errors"]:
print(f"Error: {error['message']}")
else:
results = data["data"]["search"]
print(f"Found {results['totalCount']} documents")

Pagination

The Document Search API uses cursor-based pagination. Each response includes a cursor field that points to the next page of results. To retrieve subsequent pages, pass the cursor value from the previous response as the cursor variable in your next request.

cursor = None
all_documents = []

while True:
variables = {
"filter": {
"keyword": {"query": "AI strategy"},
"date": {"preset": "LAST_30_DAYS"}
},
"limit": 20,
"sorting": {"field": "DATE", "direction": "DESC"},
"cursor": cursor,
}

response = requests.post(url, headers=headers, json={"query": query, "variables": variables})
data = response.json()
results = data["data"]["search"]

all_documents.extend(results["documents"])
cursor = results["cursor"]

if not cursor:
break

print(f"Retrieved {len(all_documents)} of {results['totalCount']} total documents")

When cursor is null or not present in the response, you have reached the last page of results.

tip

Uses the same GraphQL schema as Search API. Explore the full schema in the GraphQL Explorer.