# Federal contracts

> POST /federal/contracts looks up a company in USAspending.gov by UEI or name: federal obligations over 12 months, top agencies and NAICS codes, latest contracts.

`POST https://api.qelka.com/v1/federal/contracts`

Look up the US federal awards of a company in USAspending.gov, the official source of federal spending data: who the recipient is, its corporate parent, what it received over the last 12 months, from which agencies, in which industries, and its latest contracts. Each lookup costs 1 credit when a recipient is found; lookups that find nothing, errors and test keys are never billed.

## Request

Send the SAM.gov Unique Entity ID (UEI) of the company, or its name. A UEI finds that exact entity; a name finds the recipient with the most obligations among those whose name matches, and lists the next ones.

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `uei` | string | One of `uei` and `name` | none | The 12-character UEI, 1 to 20 characters before spaces and hyphens are removed. Lower case is accepted. |
| `name` | string | One of `uei` and `name` | none | A company name or part of it, 2 to 200 characters. |
| `fresh` | boolean | No | `false` | `true` skips the 24-hour result cache and asks USAspending.gov again. |

Send exactly one of `uei` and `name`: a body with both, or with neither, is a `400 invalid_request`.

A lookup makes up to five requests to USAspending.gov in two rounds, each with a 12-second limit, so every snippet sets a 60-second client timeout.

```bash title="cURL"
curl https://api.qelka.com/v1/federal/contracts \
  --max-time 60 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Lockheed Martin"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/federal/contracts', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'Lockheed Martin' }),
  signal: AbortSignal.timeout(60_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/federal/contracts",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"name": "Lockheed Martin"},
    timeout=60,
)
result = response.json()
print(result)
```
```php title="PHP"
<?php
$ch = curl_init('https://api.qelka.com/v1/federal/contracts');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('QELKA_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['name' => 'Lockheed Martin']),
    CURLOPT_TIMEOUT => 60,
]);
$result = json_decode(curl_exec($ch), true);
print_r($result);
```
```go title="Go"
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	payload, _ := json.Marshal(map[string]any{"name": "Lockheed Martin"})
	request, _ := http.NewRequest(http.MethodPost, "https://api.qelka.com/v1/federal/contracts", bytes.NewReader(payload))
	request.Header.Set("Authorization", "Bearer "+os.Getenv("QELKA_API_KEY"))
	request.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 60 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
		panic(err)
	}
	fmt.Println(result)
}
```
```ruby title="Ruby"
require 'json'
require 'net/http'

uri = URI('https://api.qelka.com/v1/federal/contracts')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV.fetch('QELKA_API_KEY')}"
request['Content-Type'] = 'application/json'
request.body = JSON.generate({ name: 'Lockheed Martin' })

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 60) do |http|
  http.request(request)
end
result = JSON.parse(response.body)
puts result
```

## Response

Every valid request gets a `200`. Read `status` first: only `found` fills the recipient and the lists.

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup: `lkp_` followed by 26 characters. |
| `object` | string | Always `federal_contracts`. |
| `input` | string | The `uei` or `name` you sent, without surrounding spaces. |
| `query` | string | `uei` or `name`: the field you sent. |
| `status` | string | `found`, `not_found` or `invalid`. |
| `reason` | string or null | `no_match` with `not_found`, `invalid_uei` with `invalid`, else `null`. |
| `recipient` | object or null | The recipient found. `null` unless `status` is `found`. |
| `recipient.name` | string | The name USAspending.gov records for the recipient. |
| `recipient.uei` | string or null | Its UEI. |
| `recipient.duns` | string or null | Its legacy DUNS number, when USAspending.gov still holds one. |
| `recipient.level` | string | `parent`: a corporate parent whose totals include its children. `child`: an entity with a parent. `recipient`: an entity with neither. |
| `recipient.parent` | object or null | For a `child`, its parent: `name` and `uei`, each string or null. `null` otherwise. |
| `recipient.alternate_names` | array of strings | Other names recorded for the recipient, up to 10. For a parent, they include names of its children. |
| `recipient.business_types` | array of strings | Business type codes, such as `other_than_small_business` or `manufacturer_of_goods`. |
| `recipient.address` | object or null | `line1`, `city`, `state`, `zip`, `country_code` (ISO 3166-1 alpha-3) and `congressional_district`, each string or null. |
| `recipient.url` | string | The recipient profile on USAspending.gov. |
| `obligations` | object or null | Totals of the trailing 12 months. `null` unless `status` is `found`. |
| `obligations.last_12_months` | number | Sum of every prime award transaction, contracts, grants, loans and other assistance, in US dollars. Deobligations can make it negative. |
| `obligations.transactions` | integer | Number of those transactions. |
| `period` | object | The window of `top_agencies` and `top_naics`: `from` and `to`, `YYYY-MM-DD`, the last 365 days. |
| `top_agencies` | array of objects | Awarding agencies by obligations over the period, all award types, up to 5. |
| `top_agencies.name` | string | Agency name. |
| `top_agencies.code` | string or null | Agency abbreviation, such as `DOD`. |
| `top_agencies.amount` | number | Obligations over the period, in US dollars. |
| `top_naics` | array of objects | NAICS industries of the contract obligations over the period, up to 5, with the same `name`, `code` and `amount` fields. |
| `recent_contracts` | array of objects | Latest contracts, purchase orders, delivery orders and BPA calls by date signed, up to 5. |
| `recent_contracts.award_id` | string | The Procurement Instrument Identifier (PIID) of the award. |
| `recent_contracts.description` | string or null | Description of the award. |
| `recent_contracts.amount` | number or null | Total obligated amount of the award, in US dollars. |
| `recent_contracts.date_signed` | string or null | Date of the base obligation, `YYYY-MM-DD`. |
| `recent_contracts.start_date`, `recent_contracts.end_date` | string or null | Period of performance, `YYYY-MM-DD`. |
| `recent_contracts.agency`, `recent_contracts.sub_agency` | string or null | Awarding agency and sub-agency. |
| `recent_contracts.award_type` | string or null | Contract type as USAspending.gov reports it, such as `DELIVERY ORDER` or `DEFINITIVE CONTRACT`. |
| `recent_contracts.naics_code`, `recent_contracts.naics_title` | string or null | NAICS code and title of the award. |
| `recent_contracts.url` | string or null | The award page on USAspending.gov. |
| `other_matches` | array of objects | For a name search, the next recipients by obligations of the last 12 months, up to 5: `name`, `uei`, `level` and `amount`. Empty for a UEI lookup. |
| `credits_used` | integer | Credits debited for this call: 1 when `status` is `found` with a live key, else `0`. |
| `cached` | boolean | `true` when the answer came from the 24-hour cache. |

Some arrays are cut short in this example:

```json title="Response"
{
  "id": "lkp_01M8CEKJEYE4WD4FZ4WBK4R09Z",
  "object": "federal_contracts",
  "input": "Lockheed Martin",
  "query": "name",
  "status": "found",
  "reason": null,
  "recipient": {
    "name": "LOCKHEED MARTIN CORP",
    "uei": "ZFN2JJXBLZT3",
    "duns": "834951691",
    "level": "parent",
    "parent": null,
    "alternate_names": ["ASTROTECH SPACE OPERATIONS LLC", "COMPOSITE TECHNOLOGY INC.", "DERCO AEROSPACE INC."],
    "business_types": [
      "category_business",
      "corporate_entity_not_tax_exempt",
      "manufacturer_of_goods",
      "other_than_small_business",
      "special_designations",
      "us_owned_business"
    ],
    "address": {
      "line1": "6801 ROCKLEDGE DR",
      "city": "BETHESDA",
      "state": "MD",
      "zip": "20817",
      "country_code": "USA",
      "congressional_district": "08"
    },
    "url": "https://www.usaspending.gov/recipient/b97d19b0-833c-8d8f-3a2c-157d04ea55ef-P/latest"
  },
  "obligations": { "last_12_months": 51518953111.31, "transactions": 21669 },
  "period": { "from": "2025-11-26", "to": "2026-11-26" },
  "top_agencies": [
    { "name": "Department of Defense", "code": "DOD", "amount": 50148825310.64 },
    { "name": "National Aeronautics and Space Administration", "code": "NASA", "amount": 1111118808.27 },
    { "name": "Department of Commerce", "code": "DOC", "amount": 136989987.57 }
  ],
  "top_naics": [
    { "name": "Guided Missile and Space Vehicle Manufacturing", "code": "336414", "amount": 19827468446.29 },
    { "name": "Aircraft Manufacturing", "code": "336411", "amount": 16873823470.96 }
  ],
  "recent_contracts": [
    {
      "award_id": "70Z03827FJ0000031",
      "description": "PURCHASE OF MULTIPLE FORMERS TO BE UTILIZED ON THE USCG MH-60T HELICOPTERS.",
      "amount": 11504.52,
      "date_signed": "2026-11-24",
      "start_date": "2026-11-24",
      "end_date": "2027-09-25",
      "agency": "Department of Homeland Security",
      "sub_agency": "U.S. Coast Guard",
      "award_type": "DELIVERY ORDER",
      "naics_code": "336413",
      "naics_title": "OTHER AIRCRAFT PARTS AND AUXILIARY EQUIPMENT MANUFACTURING",
      "url": "https://www.usaspending.gov/award/CONT_AWD_70Z03827FJ0000031_7008_70Z03822DJ0000017_7008"
    },
    {
      "award_id": "70Z03827FJ0000028",
      "description": "PURCHASE OF THE VARIOUS ITEMS TO BE UTILIZED ON USCG MH-60T HELICOPTERS.",
      "amount": 9754.96,
      "date_signed": "2026-11-23",
      "start_date": "2026-11-23",
      "end_date": "2027-12-13",
      "agency": "Department of Homeland Security",
      "sub_agency": "U.S. Coast Guard",
      "award_type": "DELIVERY ORDER",
      "naics_code": "336413",
      "naics_title": "OTHER AIRCRAFT PARTS AND AUXILIARY EQUIPMENT MANUFACTURING",
      "url": "https://www.usaspending.gov/award/CONT_AWD_70Z03827FJ0000028_7008_SPE4A122G0005_9700"
    }
  ],
  "other_matches": [
    { "name": "LOCKHEED MARTIN CORPORATION", "uei": "XFJMYSYFJEK4", "level": "child", "amount": 15566390489.39 },
    { "name": "LOCKHEED MARTIN CORPORATION", "uei": "G4KDGE4JFFK7", "level": "child", "amount": 14798575240.9 }
  ],
  "credits_used": 1,
  "cached": false
}
```

## Act on the status

| `status` | What it means | What to do | Billed |
|---|---|---|---|
| `found` | A recipient matched. | Read the recipient and its totals. For a name search, compare `other_matches` before you conclude: a group often has several recipients with close names. | Yes, and cached 24 hours |
| `not_found` | No recipient matches the UEI or the name (`reason: "no_match"`). | Try the legal name, a shorter part of it, or the UEI from the SAM.gov registration. A company that never received a federal award has no recipient. | No |
| `invalid` | The UEI is not 12 letters and digits without I or O (`reason: "invalid_uei"`). USAspending.gov is not asked. | Fix the UEI. | No |

Answers other than `found` are never cached, so the next request asks USAspending.gov again.

## How the lookup works

1. A UEI loses its spaces and hyphens and is turned to upper case. It must be 12 characters, letters other than I and O and digits, not starting with 0; otherwise the answer is `invalid`.
2. The UEI or the name is searched among USAspending.gov recipients, sorted by amount. For a UEI, only recipients with exactly that UEI are kept. For a name, the results are grouped by UEI, keeping the entry with the largest amount, and a parent when two tie; the first is the recipient, the next 5 are `other_matches`.
3. Four requests then run together: the recipient profile for its latest 12 months, its obligations of the period by awarding agency over all award types, its obligations by NAICS code over contracts only, and its latest contract awards (types A to D: BPA calls, purchase orders, delivery orders and definitive contracts), searched by UEI, or by DUNS number or name for a recipient without one, and sorted by date signed.
4. The profile gives the name, UEI, DUNS, level, parent, alternate names, business types, address and the 12-month totals. If it cannot be read, `obligations.last_12_months` falls back to the amount of the search and `transactions` to `0`.

The Department of Defense publishes its contract awards with a 90-day delay, so its latest contracts are missing from `recent_contracts` and from the period totals. Subawards are not counted anywhere.

## Examples

### Search a name with a test key

Test keys return a sample recipient without calling USAspending.gov: a name that contains `nomatch` returns `not_found`, the UEI `TESTUEX12345` returns the sample parent, any other valid UEI returns `not_found`, and any other name returns the sample below. With a test key in `QELKA_API_KEY`, this request returns:

```bash title="cURL"
curl https://api.qelka.com/v1/federal/contracts \
  --max-time 60 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Acme Widgets"}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/federal/contracts', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'Acme Widgets' }),
  signal: AbortSignal.timeout(60_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/federal/contracts",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"name": "Acme Widgets"},
    timeout=60,
)
result = response.json()
print(result)
```

```json title="Response"
{
  "id": "lkp_01M8CG2T5Q0V9W7XKJ4R6B3N1D",
  "object": "federal_contracts",
  "input": "Acme Widgets",
  "query": "name",
  "status": "found",
  "reason": null,
  "recipient": {
    "name": "ACME WIDGETS CORPORATION",
    "uei": "TESTUEX12345",
    "duns": null,
    "level": "parent",
    "parent": null,
    "alternate_names": ["ACME WIDGETS CORP"],
    "business_types": ["category_business", "corporate_entity_not_tax_exempt", "other_than_small_business"],
    "address": {
      "line1": "1 TEST WAY",
      "city": "ARLINGTON",
      "state": "VA",
      "zip": "22201",
      "country_code": "USA",
      "congressional_district": "08"
    },
    "url": "https://www.usaspending.gov/recipient/c1d2e3f4-0000-4000-8000-000000000001-P/latest"
  },
  "obligations": { "last_12_months": 12500000, "transactions": 42 },
  "period": { "from": "2025-11-26", "to": "2026-11-26" },
  "top_agencies": [
    { "name": "Department of Defense", "code": "DOD", "amount": 10000000 },
    { "name": "General Services Administration", "code": "GSA", "amount": 2500000 }
  ],
  "top_naics": [
    { "name": "Other Measuring and Controlling Device Manufacturing", "code": "334519", "amount": 9000000 }
  ],
  "recent_contracts": [
    {
      "award_id": "TEST0001F0001",
      "description": "TEST MODE AWARD: SENSOR MAINTENANCE",
      "amount": 1200000,
      "date_signed": "2026-06-01",
      "start_date": "2026-06-01",
      "end_date": "2027-05-31",
      "agency": "Department of Defense",
      "sub_agency": "Department of the Navy",
      "award_type": "DELIVERY ORDER",
      "naics_code": "334519",
      "naics_title": "OTHER MEASURING AND CONTROLLING DEVICE MANUFACTURING",
      "url": null
    }
  ],
  "other_matches": [
    { "name": "ACME WIDGETS SERVICES LLC", "uei": "TESTUEX67890", "level": "recipient", "amount": 850000 }
  ],
  "credits_used": 0,
  "cached": false
}
```

## Errors

| Status | Type | When |
|---|---|---|
| 400 | [invalid_request](https://qelka.com/docs/errors#invalid_request) | Both or neither of `uei` and `name`, `uei` empty or longer than 20 characters, `name` shorter than 2 or longer than 200 characters, a body that is not a JSON object, or a field the request table does not list |
| 401 | [invalid_api_key](https://qelka.com/docs/errors#invalid_api_key) | The key is missing, unknown or revoked |
| 402 | [insufficient_credits](https://qelka.com/docs/errors#insufficient_credits) | Your balance is less than 1 credit (live keys only) |
| 403 | [forbidden](https://qelka.com/docs/errors#forbidden) | The key is restricted to other endpoints |
| 405 | [invalid_request](https://qelka.com/docs/errors#invalid_request) | The method is not `POST` |
| 429 | [rate_limited](https://qelka.com/docs/errors#rate_limited) | Too many requests: wait `Retry-After` seconds |
| 500 | [internal_error](https://qelka.com/docs/errors#internal_error) | Unexpected error on our side: retry with backoff |
| 502 | [upstream_unavailable](https://qelka.com/docs/errors#upstream_unavailable) | USAspending.gov could not be reached, answered with an error or did not answer in time: retry later |

No error is billed. A UEI that fails the format check is not an error: it is a `200` with `status: "invalid"`, and a company that USAspending.gov does not know is a `200` with `status: "not_found"`.

## Related

- [Federal contracts API](https://qelka.com/products/federal-contracts)
- Free tools: [federal contractor lookup](https://qelka.com/tools/federal-contractor-lookup), [NAICS code lookup](https://qelka.com/tools/naics-code-lookup)
- [Batch](https://qelka.com/docs/api-reference/batch): up to 100 lookups in one call, each item with `type: "federal_contracts"`
- [Bulk](https://qelka.com/docs/api-reference/bulk): a whole column of UEIs or company names with `type=federal_contracts`
- [Caching](https://qelka.com/docs/caching), [Errors](https://qelka.com/docs/errors), [Test mode](https://qelka.com/docs/test-mode)
