Data source: USASpending.gov
Overview
USASpending wraps USASpending.gov, handling authentication, pagination, and rate limits for you. This tutorial covers all 6 tools with working code examples you can copy and run.
Prerequisites
- Sign up at https://context.gnist.ai/signup for a free API key (100 calls/day).
- Choose your integration method: MCP protocol or REST API.
Connect via MCP
Add to your MCP client config (Claude Desktop, Cursor, etc.):
{
"mcpServers": {
"gnist-usaspending": {
"url": "https://context.gnist.ai/mcp/usaspending/",
"headers": {
"Gnist-API-Key": "YOUR_API_KEY"
}
}
}
}
Tools (6)
search_awards
Search USASpending.gov for federal awards (contracts, grants, loans, direct payments). USASpending.gov is the official source for US federal government spending data, covering $6–7 trillion annually from FY2008–present, updated nightly. Args: query: Keywords to search for (e.g. "Lockheed Martin", "cybersecurity", "COVID-19 relief"). award_type: Filter by award category. Values: "contracts" (default), "grants", "loans", "direct_payments". agency: Filter by awarding agency name (e.g. "Department of Defense", "Department of Health and Human Services"). date_from: Only include awards starting on or after this date (YYYY-MM-DD). date_to: Only include awards starting on or before this date (YYYY-MM-DD). limit: Number of results to return (1–50, default 10). Sorted by award amount descending. Returns: Dict with 'count', 'has_next', and 'awards' list. Each award includes award_id, recipient_name, award_amount, awarding_agency, start/end dates, description, and NAICS industry classification.
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | required | Keywords to search for (e.g. "Lockheed Martin", "cybersecurity", "COVID-19 relief"). |
award_type | any | optional | Filter by award category. Values: "contracts" (default), "grants", "loans", "direct_payments". |
agency | any | optional | Filter by awarding agency name (e.g. "Department of Defense", "Department of Health and Human Services"). |
date_from | any | optional | Only include awards starting on or after this date (YYYY-MM-DD). |
date_to | any | optional | Only include awards starting on or before this date (YYYY-MM-DD). |
limit | integer | optional | Number of results to return (1–50, default 10). Sorted by award amount descending. (default: 10) |
curl -X POST "https://context.gnist.ai/mcp/usaspending/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "search_awards", "arguments": {"query": "Lockheed Martin"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/usaspending/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'query': 'Lockheed Martin'}, 'name': 'search_awards'}},
)
print(resp.json())
get_award
Fetch detailed information for a specific federal award. Use the generated_internal_id from search_awards results (e.g. "CONT_AWD_N0001917C0001_9700_-NONE-_-NONE-") to look up full details including recipient info, subaward data, contracting details, and place of performance. Args: award_id: The generated_unique_award_id or generated_internal_id from search results. Returns: Dict with full award details: obligation amounts, recipient, agencies, NAICS/PSC codes, subaward count, place of performance, and period of performance dates.
| Parameter | Type | Required | Description |
|---|---|---|---|
award_id | string | required | The generated_unique_award_id or generated_internal_id from search results. |
curl -X POST "https://context.gnist.ai/mcp/usaspending/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_award", "arguments": {"award_id": "12345"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/usaspending/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'award_id': '12345'}, 'name': 'get_award'}},
)
print(resp.json())
get_recipient
Search for or fetch a federal award recipient (contractor, grantee, etc.). Search by name/keyword to find recipients, or pass a recipient_id (from search_awards results) to get a full profile with alternate names, business types, and location. Args: keyword: Recipient name or keyword to search (e.g. "Raytheon", "Johns Hopkins"). recipient_id: Specific recipient hash ID for full profile lookup (e.g. "6cf5fb1b-4988-d087-5dc1-70939d8fc6c4-C"). limit: Number of search results (1–50, default 10). Ignored when using recipient_id. Returns: Dict with 'count', 'total', and 'recipients' list. Each includes name, UEI, total award amount, and (for profile lookups) business types, location, and alternate names.
| Parameter | Type | Required | Description |
|---|---|---|---|
keyword | any | optional | Recipient name or keyword to search (e.g. "Raytheon", "Johns Hopkins"). |
recipient_id | any | optional | Specific recipient hash ID for full profile lookup (e.g. "6cf5fb1b-4988-d087-5dc1-70939d8fc6c4-C"). |
limit | integer | optional | Number of search results (1–50, default 10). Ignored when using recipient_id. (default: 10) |
curl -X POST "https://context.gnist.ai/mcp/usaspending/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_recipient", "arguments": {"keyword": "Raytheon"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/usaspending/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'keyword': 'Raytheon'}, 'name': 'get_recipient'}},
)
print(resp.json())
get_agency_spending
Fetch budgetary resources for a US federal agency. Common toptier agency codes: - "097" — Department of Defense - "075" — Department of Health and Human Services - "012" — Department of Agriculture - "069" — Department of Transportation - "089" — Department of Energy - "028" — Social Security Administration Args: agency_code: Three-digit toptier agency code (e.g. "097" for DoD). fiscal_year: Federal fiscal year (Oct–Sep). Omit for most recent available. Returns: Dict with toptier_code, fiscal_year, agency_budgetary_resources (total budget authority), agency_total_obligated (committed), agency_total_outlayed (spent), and total_budgetary_resources (all-government total for comparison).
| Parameter | Type | Required | Description |
|---|---|---|---|
agency_code | string | required | Three-digit toptier agency code (e.g. "097" for DoD). |
fiscal_year | any | optional | Federal fiscal year (Oct–Sep). Omit for most recent available. |
curl -X POST "https://context.gnist.ai/mcp/usaspending/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "get_agency_spending", "arguments": {"agency_code": "097"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/usaspending/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'agency_code': '097'}, 'name': 'get_agency_spending'}},
)
print(resp.json())
spending_by_geography
Aggregate federal spending by geographic area (state, county, or congressional district). Useful for analyzing where federal money flows — e.g. which states receive the most defense contracts, or where COVID relief grants were concentrated. Args: keywords: Search terms to filter spending (e.g. ["cybersecurity"], ["COVID-19", "relief"]). geo_layer: Geographic granularity. Values: "state", "county", "district" (congressional district). Default "state". scope: What location to aggregate by. Values: "place_of_performance" (where work happens), "recipient_location" (where recipient is based). Default "place_of_performance". award_type: Filter by category: "contracts", "grants", "loans", "direct_payments". Omit for all types. date_from: Start date filter (YYYY-MM-DD). date_to: End date filter (YYYY-MM-DD). Returns: Dict with 'scope', 'geo_layer', 'count', and 'results' list. Each result includes shape_code (state/county/district code), display_name, aggregated_amount, population, and per_capita spending.
| Parameter | Type | Required | Description |
|---|---|---|---|
keywords | list[string] | required | Search terms to filter spending (e.g. ["cybersecurity"], ["COVID-19", "relief"]). |
geo_layer | string | optional | Geographic granularity. Values: "state", "county", "district" (congressional district). Default "state". (default: state) |
scope | string | optional | What location to aggregate by. Values: "place_of_performance" (where work happens), "recipient_location" (where recipient is based). Default "place_of_performance". (default: place_of_performance) |
award_type | any | optional | Filter by category: "contracts", "grants", "loans", "direct_payments". Omit for all types. |
date_from | any | optional | Start date filter (YYYY-MM-DD). |
date_to | any | optional | End date filter (YYYY-MM-DD). |
curl -X POST "https://context.gnist.ai/mcp/usaspending/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "spending_by_geography", "arguments": {"keywords": "[\"cybersecurity\"]"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/usaspending/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'keywords': '["cybersecurity"]'},
'name': 'spending_by_geography'}},
)
print(resp.json())
report_feedback
Report a bug, feature request, or general feedback for this data source. Use this when something doesn't work as expected, when you'd like a new feature, or when you have suggestions for improvement. Args: feedback: Describe the issue or suggestion. feedback_type: One of 'bug', 'feature_request', or 'general'.
| Parameter | Type | Required | Description |
|---|---|---|---|
feedback | string | required | |
feedback_type | string | optional | (default: general) |
curl -X POST "https://context.gnist.ai/mcp/usaspending/" \
-H "Content-Type: application/json" \
-H "Gnist-API-Key: YOUR_API_KEY" \
-d '{"jsonrpc": "2.0", "method": "tools/call", "id": 1, "params": {"name": "report_feedback", "arguments": {"feedback": "example"}}}'
import httpx
resp = httpx.post(
"https://context.gnist.ai/mcp/usaspending/",
headers={"Gnist-API-Key": "YOUR_API_KEY"},
json={'id': 1,
'jsonrpc': '2.0',
'method': 'tools/call',
'params': {'arguments': {'feedback': 'example'}, 'name': 'report_feedback'}},
)
print(resp.json())
Common Patterns
Use
search_awards to find items, then get_award to get full details. This two-step pattern is common for exploring data before drilling down.Several tools support
limit, offset, or page parameters. Start with small limits during development, then increase for production queries.Use date range parameters to narrow results to a specific time window. Dates are typically in
YYYY-MM-DD format.FAQ
What data does USASpending provide?
U.S. federal spending data — contracts, grants, and agency budgets. It exposes 6 tools: search_awards, get_award, get_recipient, get_agency_spending, spending_by_geography, report_feedback.
What do I need to get started?
A Gnist API key (free tier: 100 calls/day). Sign up at https://context.gnist.ai/signup.
What format does the USASpending API return?
JSON, via either MCP protocol (JSON-RPC 2.0) or REST API.