GovInfo API

repository·main·Indexed 42 days ago

https://github.com/usgpo/api

Programmatic access to official publications from all three branches of the Federal Government. The API allows developers to search, discover, and retrieve content and metadata stored in self-describing packages via services including Search, Collections, Published, Related, and Packages. It supports an MCP server for LLM integration and requires an api.data.gov key for authentication.

Tokens
3K
Snippets
10
Records
17
Agent score
5%

What's inside GovInfo API

  1. Configure the GovInfo MCP server

    main

    To allow an LLM client to access GovInfo content and metadata via the Model Context Protocol (MCP), you must add the GovInfo MCP server to your client's configuration file (typically mcp.json).

    You will need a GovInfo API key. You can sign up for one at govinfo.gov/api-signup or use an existing api.data.gov key.

    Add the following configuration to your mcp.json file, replacing YOUR_GOVINFO_API_KEY with your actual key.

    {
      "mcpServers": {
        "mcp-govinfo": {
          "url": "https://api.govinfo.gov/mcp",
          "headers": {
            "x-api-key": "YOUR_GOVINFO_API_KEY"
          }
        }
      }
    }
  2. Handle 503 errors for ZIP or MODS generation

    main

    When requesting a ZIP or MODS file that is not currently in the cache, the API may return an HTTP 503 response. This indicates the system is currently generating the file.

    Action required:

    1. Check the Retry-After header in the response. It typically contains a value of 30 (seconds).
    2. Wait for the specified number of seconds before retrying the request.
    3. If the file is still being generated, you may receive another 503 with a new Retry-After header.

    Example error body:

    {"message":"Generating ZIP file. Please retry your request again after 30 seconds"}
  3. Handle 401 Unauthorized (API_KEY_MISSING)

    main

    An HTTP 401 error with the message API_KEY_MISSING indicates that the request did not include a valid API key.

    Solutions:

    • Use the DEMO_KEY for temporary testing (note that it has lower rate limits).
    • Obtain a regular API key to access higher limits and other Federal APIs via api.data.gov.
  4. Handle 429 Rate Limit errors

    main

    The GovInfo API implements rate limiting to prevent resource exhaustion. If you exceed the limit, the API will return a 429 status code.

    To monitor your usage, inspect the following response headers:

    • X-RateLimit-Limit: The total number of requests allowed in the current window.
    • X-RateLimit-Remaining: The number of requests remaining in the current window.

    Note: The DEMO_KEY has a lower limit than regular user keys.

    X-RateLimit-Limit: 40
    X-RateLimit-Remaining: 39
  5. Get packages by publication date (Published Service)

    main

    The Published Service provides a list of packages based on their dateIssued (the publication date of the content), rather than the system update time.

    Endpoint Format: https://api.govinfo.gov/published/{dateIssuedStartDate}/{dateIssuedEndDate}?offsetMark={startingRecord}&pageSize={number}&collection={comma-separated-list}&api_key={key}

    Required Parameters:

    • dateIssuedStartDate: Earliest package date (YYYY-MM-DD).
    • offsetMark: Starting record. Use * for the first request.
    • pageSize: Number of records per request.
    • collection: Comma-separated list of collection codes (e.g., BILLS,BILLSTATUS).

    Optional Parameters:

    • dateIssuedEndDate: Latest package date (YYYY-MM-DD).
    • docClass: Filter by collection-specific categories (e.g., s, hr for BILLS; HOUSE, SENATE for CREC).
    • congress: Congress number (e.g., 116).
    • modifiedSince: ISO 8601 timestamp to request only packages modified since a specific time (useful for tracking updates).
    https://api.govinfo.gov/published/2019-01-01/2019-07-31?offsetMark=*&pageSize=100&collection=BILLS&api_key=DEMO_KEY
  6. Use `searchGovInfo` to discover content

    main

    The searchGovInfo tool is a discovery tool used to find official GovInfo content and metadata.

    When called, it returns basic information for matching results, including:

    • Title of the result
    • Unique identifiers
    • Official publication dates
    • Last system update times
    • A link to the associated GovInfo details page
    • A brief teaser of the content
  7. Retrieve a Granule Summary

    main

    A Granule Summary provides basic metadata and links to all available content and metadata formats (including ZIP files) for a specific granule. This is similar to the Package Summary but operates at the individual granule level.

    Example endpoints:

    • Congressional Record (CREC): https://api.govinfo.gov/packages/CREC-2018-07-10/granules/CREC-2018-07-10-pt1-PgD782/summary?api_key=DEMO_KEY
    • Federal Register (FR): https://api.govinfo.gov/packages/FR-2018-04-12/granules/2018-07777/summary?api_key=DEMO_KEY
  8. Retrieve related content (Related Service)

    main

    The Related Service identifies and retrieves metadata about content related to a specific access ID.

    Pattern: https://api.govinfo.gov/related/{accessId}

    Example: https://api.govinfo.gov/related/BILLS-116hr748enr?api_key=DEMO_KEY

    This returns a list of relationships that can be followed to retrieve specific documents.

    Common Relationships:

    • From BILLS/PLAW: Related Bill Versions, Bill History, Presidential Signing Statements, Public/Private Laws, Committee Prints, Reports, U.S. Code References, and Statutes at Large References.
    • From FR (Federal Register): Related FR documents by RIN (Regulation Identifier Number) and CFR Citations.
    • From CHRG (Hearings): Related Hearings (parts or errata).
    https://api.govinfo.gov/related/BILLS-116hr748enr?api_key=DEMO_KEY
  9. Use the Search Service to find content

    main

    The Search Service allows programmatic requests against the GovInfo search engine using a POST request. This returns results similar to the GovInfo web interface.

    Sample Request:

    curl --location 'https://api.govinfo.gov/search' \
    --data '{
        "query":"collection:(USCOURTS) and naturesuit:(Securities, Commodities, Exchange) courttype:appellate",
        "pageSize":"100",
        "offsetMark":"*",
        "sorts":[
            {
                "field":"score",
                "sortOrder":"DESC"
            }
        ]
    }'
    curl --location 'https://api.govinfo.gov/search' \
    --data '{
        "query":"collection:(USCOURTS) and naturesuit:(Securities, Commodities, Exchange) courttype:appellate",
        "pageSize":"100",
        "offsetMark":"*",
        "sorts":[
            {
                "field":"score",
                "sortOrder":"DESC"
            }
        ]
    }'
  10. Get packages modified within a time frame (Collections Service)

    main

    The Collections Service allows you to retrieve a list of packageIds that have been added or modified within a specific period for a given collection.

    Required Parameters:

    • collectionCode: The code of the collection (e.g., BILLS, CREC, USCOURTS).
    • lastModifiedStartDate: The start of the window for the lastModified value (ISO 8601 format).
    • pageSize: Number of results (max 1000).

    Pagination: Use offsetMark=* for the initial request. The API will return the correct offsetMark for the next page in the nextPage key of the response. This allows traversing results beyond the first 10,000 records.

    Note on Dates: lastModifiedStartDate and lastModifiedEndDate search against the time a package was added or updated in the GovInfo system. This is distinct from the content's actual publication or issue date.

    https://api.govinfo.gov/collections/BILLS/2025-01-01T00:00:00Z/?offsetMark=*&pageSize=100&api_key=DEMO_KEY
  11. List available collections

    main

    To get a JSON list of all collections available in the system, perform a GET request to the /collections endpoint. The response includes collectionCode, collectionName, packageCount, and granuleCount (where applicable).

    https://api.govinfo.gov/collections?api_key=DEMO_KEY