Skip to main content

Document Search API

The Document Search API is a companion utility to the Agent API. When an agent returns a document reference, use this API to look up document-level metadata for that reference — for example, the associated company and its ticker, the release date, and the page count.

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
pageCount
companies {
name
primaryTickerCode
}
}
}
}

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

ACCESS_TOKEN = os.environ["ALPHASENSE_ACCESS_TOKEN"] # see Authentication guide

headers = {
"x-api-key": os.environ["ALPHASENSE_API_KEY"],
"clientid": os.environ["ALPHASENSE_CLIENT_ID"],
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json",
}

query = """
query SearchDocuments($filter: SearchFilter!, $limit: Int!, $sorting: SearchSorting!) {
search(filter: $filter, limit: $limit, sorting: $sorting) {
cursor
totalCount
documents {
id
title
releasedAt
pageCount
companies { name primaryTickerCode }
}
}
}
"""

variables = {
"filter": {"companies": {"ids": ["AAPL"]}},
"limit": 20,
"sorting": {"field": "DATE", "direction": "DESC"},
}

response = requests.post(
"https://api.alpha-sense.com/gql",
headers=headers,
json={"query": query, "variables": variables},
)
print(response.json())

Example Response

{
"data": {
"search": {
"cursor": "eyJsYXN0SWQiOiIxMjM0NTY3ODkwIn0=",
"totalCount": 342,
"documents": [
{
"releasedAt": 1731680400000,
"pageCount": 24,
"companies": [{"name": "Apple Inc.", "primaryTickerCode": "AAPL"}]
}
]
}
}
}

Pagination

Responses are paginated with a cursor. To fetch the next page, pass the previous response's cursor value back as the cursor variable. When cursor is null, you've reached the last page.

tip

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