canonical: https://jentic.com/apis/code.gov/code-gov-main

# Code.gov API

The Code.gov API is the public interface to the U.S. Federal Government's open source software inventory, created under the Federal Source Code Policy. It exposes endpoints to search and retrieve repository metadata, list publishing agencies, surface programming languages used across federal code, and check the publishing status of each agency's code.json. Civic developers, researchers, and federal contractors use it to find reusable code, evaluate compliance with the policy, and study how federal teams build software.

## For AI agents

Search and retrieve U.S. federal government open source repository metadata, agencies, languages, and publishing status from Code.gov.

## Scope

Does not host repository contents, modify federal code records, or expose non-public agency data - use for discovery and metadata over the public federal open source inventory only.

## Capabilities

- Search the federal open source repository corpus by keyword, agency, or language
- Retrieve a single repository record with license, contact, and labor hours
- List federal agencies that publish a code.json under the Federal Source Code Policy
- Read agency-level publishing status, fetch issues, and last fetched timestamp
- List programming languages with the count of federal repositories using each
- Pull popular terms used across federal repository metadata
- Check the deployed Code.gov API version, git commit, and source repository

## Use cases

### Reuse-First Federal Procurement

Federal contractors and procurement officers use Code.gov to satisfy the reuse-first requirement of the Federal Source Code Policy before commissioning new work. The /repos endpoint accepts keyword search and `/repos/{repoId}` returns the metadata, license, and contact for evaluating whether existing code can be adapted to the new requirement.

Example prompt: Search /repos for the keyword 'document classification' and return the top 10 candidates with license and contact information.

### Federal Open Source Compliance Tracking

Civic technologists and oversight researchers track which federal agencies are publishing under the Federal Source Code Policy and which are failing using the agency and status endpoints. /agencies, `/status/{agencyName}/issues`, and `/status/{agencyName}/fetched` expose the data needed to publish compliance scorecards and historical trends.

Example prompt: List all agencies, then for each call `/status/{agencyName}/fetched` and report any whose last fetch is older than 30 days.

### Federal Software Research Datasets

Academic and policy researchers studying how federal software is built use the corpus-level Code.gov endpoints. /languages returns repository counts per language and /terms returns popular tags, which together support quantitative research into language adoption, license preferences, and topical concentration of federally-funded code.

Example prompt: Pull /languages and /terms and produce a CSV summarising repositories by language and the top 50 terms by count.

### AI Agent Federal Repository Search

AI agents helping public sector teams find existing federal code use the Code.gov API through Jentic. The agent searches Jentic for 'search Code.gov repositories', loads the operation, and runs queries against /repos. Because the API is unauthenticated, Jentic forwards requests directly while still giving the agent schema-driven discovery and consistent execution semantics.

Example prompt: Search Jentic for 'search Code.gov repos', load the operation, and search for repositories tagged 'cybersecurity'.

## Key endpoints

| Method | Path | Description |
| --- | --- | --- |
| GET | `/repos` | Search federal open source repositories |
| GET | `/repos/{repoId}` | Retrieve a single repository by ID |
| GET | `/agencies` | List federal agencies |
| GET | `/agencies/{agency_acronym}` | Retrieve metadata for a single agency |
| GET | `/languages` | List languages with repository counts |
| GET | `/terms` | List popular terms across the corpus |
| GET | `/status/{agencyName}/issues` | Get publishing issues for an agency |
| GET | `/version` | Get the deployed API version |

## Key resources

- **Repos** — Search and retrieve federal open source repository metadata
- **Agencies** — List federal agencies and inspect agency metadata
- **Languages** — List programming languages with repository counts
- **Terms** — Popular terms across federal repository metadata
- **Status** — Per-agency publishing status, issues, and last fetched timestamps
- **Version** — Deployed API version, git commit, and source repository

## Why Jentic

- **Setup:** Code.gov is unauthenticated in the spec, so wiring it by hand mostly means targeting api.code.gov/api and, if you want higher rate limits, attaching an api.data.gov key on every request. Through Jentic you install once, import the Code.gov API from the API Directory, store that optional key once, and your agent calls it.
- **Permission scoping:** Code.gov puts the resource id in the URL path (`/repos/{repoId}` and `/agencies/{agency_acronym}`), so a rule can pin your agent to one repository or agency record. Since the API serves only public read operations, you choose which of those reads the agent may call and nothing outside that set runs.
- **Credential handling:** If you attach an api.data.gov key for higher rate limits, it is stored once, encrypted, by your own Jentic One instance and injected at execution time. It never enters the agent's prompt, logs, or context.
- **Discovery method:** Agents search Jentic by intent such as 'search federal open source code' or 'list repositories for an agency', and Jentic returns the matching Code.gov operation with its input schema so the agent calls the right endpoint without browsing the reference docs.

## Related APIs

- **GitHub REST API** — Hosts many federal repositories indexed by Code.gov
- **Code.gov API (code-gov)** — Same Code.gov API exposed under the 'code-gov' slug
- **Data.gov API** — Federal open data catalogue covering datasets beyond source code

## FAQ

### What authentication does the Code.gov API use?

The OpenAPI spec declares no security schemes - the Code.gov API is publicly accessible without an authenticated bearer or API key. In practice api.data.gov fronts the service and applies a default rate-limit tier; through Jentic the request is forwarded with no credentials attached unless the consumer chooses to register an api.data.gov key.

### Can I retrieve a specific repository by ID with the Code.gov API?

Yes. Use GET `/repos/{repoId}` where repoId is the unique identifier returned in the /repos search response. The response includes name, description, repository URL, contact, agency, license permissions, and labor hours for the repository.

### What are the rate limits for the Code.gov API?

The OpenAPI spec does not declare a rate limit. The Code.gov service is fronted by api.data.gov which applies the default unauthenticated tier. For higher throughput register an api.data.gov key and pass it via the api_key query parameter or X-API-Key header as documented by api.data.gov.

### How do I search federal repositories through Jentic?

Search Jentic for 'search Code.gov repositories', load the GET /repos operation, and execute it with your keyword. Install with pip install jentic and use the standard async search, load, and execute flow.

### Can I see which agencies are failing to publish code.json?

Yes. GET `/status/{agencyName}/issues` returns the issues encountered while fetching that agency's code.json file, and GET `/status/{agencyName}/fetched` returns the last successful fetch time. Pair the two to identify agencies that are consistently failing or stale.

### How does Code.gov decide which repositories to include?

Code.gov ingests each federal agency's code.json file as required by the Federal Source Code Policy and indexes the listed repositories. The /agencies endpoint shows which agencies are tracked and the /status endpoints expose how recent and complete each ingestion is.

### Can I limit what my agent is allowed to do with the Code.gov API?

Yes. Because you run Jentic One yourself, your own rules decide which Code.gov operations the agent may call, so you can allow only reads like GET /repos or GET /agencies and block everything else. Since Code.gov puts the resource id in the URL path (`/repos/{repoId}` and `/agencies/{agency_acronym}`), a rule can pin the agent to a single repository or agency record. The API serves only public read operations, so the agent can never modify federal code data, and any optional api.data.gov key you attach is injected at execution time rather than exposed to the agent.
