Credit Usage API
The aiUsage query reports how your organization consumes AI credits across the AlphaSense API. Use
it to see every GenSearch, ThinkLonger, and DeepResearch operation your team has run — who triggered
it, when, which mode, and how many credits it cost.
Typical uses:
- Monitor consumption — track how your team uses AI features.
- Analyze patterns — see which AI modes are used most.
- Plan capacity — make informed decisions about credit allocation.
- Audit activity — pull historical usage for compliance and reporting.
Prerequisites
| Requirement | Detail |
|---|---|
| API client | Available to external API clients only. |
| Feature flag | The ai:gensearch feature must be enabled on your account. Contact your account team to enable it. |
| Authentication | A valid access token. See SSO Authentication or Authentication (Username & Password). |
Query
aiUsage takes an input object and returns a paginated list of usage records. All arguments are
optional — call it with no filters to get the most recent activity.
query AiUsage($input: AiUsageInput!) {
aiUsage(input: $input) {
nodes {
messageId
triggeredAt
contactEmail
mode
platform
credits
}
totalCount
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
Input Parameters
| Parameter | Type | Description |
|---|---|---|
from | String | Start date (inclusive), YYYY-MM-DD. Omit for no lower bound. |
to | String | End date (inclusive), YYYY-MM-DD. Omit for no upper bound. |
limit | Int | Records to return. Default 20, maximum 100. |
offset | Int | Number of records to skip. Use with limit to paginate. |
Response Fields
| Field | Type | Description |
|---|---|---|
messageId | String | Unique identifier for the AI request. |
triggeredAt | DateTime | When the AI feature was used (ISO 8601). |
contactEmail | String | Email of the user who triggered the request. |
mode | String | AI mode used (GenSearch, ThinkLonger, DeepResearch). |
platform | String | Client identifier (your API client ID). |
credits | Int | Number of AI credits consumed. |
totalCount | Int | Total records matching your filters. |
pageInfo | Object | Cursor flags: hasNextPage, hasPreviousPage, startCursor, endCursor. |
Get recent AI usage
Retrieve the 20 most recent AI operations.
- Python
- JavaScript
- cURL
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 AiUsage($input: AiUsageInput!) {
aiUsage(input: $input) {
nodes { messageId triggeredAt contactEmail mode credits }
totalCount
}
}
"""
variables = {"input": {"limit": 20, "offset": 0}}
response = requests.post(
"https://api.alpha-sense.com/gql",
headers=headers,
json={"query": query, "variables": variables},
)
print(response.json())
const ACCESS_TOKEN = process.env.ALPHASENSE_ACCESS_TOKEN // see Authentication guide
const query = `
query AiUsage($input: AiUsageInput!) {
aiUsage(input: $input) {
nodes { messageId triggeredAt contactEmail mode credits }
totalCount
}
}
`
const variables = {input: {limit: 20, offset: 0}}
const response = await fetch('https://api.alpha-sense.com/gql', {
method: 'POST',
headers: {
'x-api-key': process.env.ALPHASENSE_API_KEY,
clientid: process.env.ALPHASENSE_CLIENT_ID,
Authorization: `Bearer ${ACCESS_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({query, variables}),
})
console.log(await response.json())
curl --location --request POST 'https://api.alpha-sense.com/gql' \
--header "x-api-key: $ALPHASENSE_API_KEY" \
--header "clientid: $ALPHASENSE_CLIENT_ID" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header 'Content-Type: application/json' \
--data-raw '{
"query": "query AiUsage($input: AiUsageInput!) { aiUsage(input: $input) { nodes { messageId triggeredAt contactEmail mode credits } totalCount } }",
"variables": { "input": { "limit": 20, "offset": 0 } }
}'
Example Response
{
"data": {
"aiUsage": {
"nodes": [
{
"messageId": "msg-abc123",
"triggeredAt": "2025-11-19T10:30:00.000Z",
"contactEmail": "user@company.com",
"mode": "GenSearch",
"credits": 10
},
{
"messageId": "msg-def456",
"triggeredAt": "2025-11-19T10:25:00.000Z",
"contactEmail": "analyst@company.com",
"mode": "ThinkLonger",
"credits": 25
}
],
"totalCount": 1250
}
}
}
More examples
Filter by date range
Pull usage for a single month — useful for reporting and credit reconciliation.
query MonthlyUsage {
aiUsage(input: {from: "2025-11-01", to: "2025-11-30", limit: 100, offset: 0}) {
nodes {
triggeredAt
contactEmail
mode
credits
}
totalCount
}
}
Total credits used
Aggregate credits over a period in your application layer.
// Sum all credits, and break the total down by mode
const records = response.data.aiUsage.nodes
const totalCredits = records.reduce((sum, r) => sum + r.credits, 0)
const creditsByMode = records.reduce((acc, r) => {
acc[r.mode] = (acc[r.mode] || 0) + r.credits
return acc
}, {})
Usage for a specific user
The query returns all usage for your client. To report on one user, filter by contactEmail after
you receive the results.
const userRecords = response.data.aiUsage.nodes.filter(
r => r.contactEmail === 'analyst@company.com',
)
Pagination
Results are paged with limit and offset. The default limit is 20 and the maximum is 100;
use 50–100 for batch processing. Check pageInfo.hasNextPage to decide whether to fetch more,
and advance offset by your limit each request.
async function fetchAllUsage(from, to) {
const limit = 100
let offset = 0
let hasMore = true
const all = []
while (hasMore) {
const response = await fetchUsage(from, to, limit, offset) // your POST helper
all.push(...response.data.aiUsage.nodes)
hasMore = response.data.aiUsage.pageInfo.hasNextPage
offset += limit
}
return all
}
Error handling
Feature not enabled
{
"errors": [
{
"message": "No permission to access AI GenSearch feature",
"extensions": {"code": "BAD_USER_INPUT"}
}
]
}
This will only be available if you are on a usage based plan.
- Credits & Rate Limits — how credits are metered across modes.
- Credit Usage Dashboard — the admin web-app view of the same usage data, with summary metrics, projections, and per-user export.
- GenSearch Modes and Inputs — the AI modes whose usage this query reports.
- Authentication (Username & Password) — password-grant access tokens.