# Connect OpenAI Responses API to SAM.gov data

To use SAM.gov data from the OpenAI Responses API, add a tool of type mcp with server_label samgovapi, server_url https://samgovapi.io/api/mcp, headers {"Authorization": "Bearer <key>"} and require_approval set to never or to an allow list. OpenAI calls the server during the response and returns the tool results in the output.

With the Responses API, OpenAI's servers make the MCP calls, so your code sends one request and gets an answer grounded in SAM.gov data. The key travels in the request's headers field on every call and is not stored by OpenAI.

- Connects with: MCP
- MCP server: https://samgovapi.io/api/mcp
- REST base: https://samgovapi.io/api/v1
- Auth: Authorization: Bearer <key>, kept in SAMGOVAPI_API_KEY

## Get a key

Free key at https://samgovapi.io/sign-up, or have the agent call start_signup and approve the link it shows you. Read the key from the environment in your own code and send it with each request.

## Set up OpenAI Responses API

1. Send a request with the MCP tool: allowed_tools keeps the model to the tools you expect, which also keeps the tool list small.

Python:

```python
import os
from openai import OpenAI

client = OpenAI()
resp = client.responses.create(
    model="gpt-5",
    tools=[{
        "type": "mcp",
        "server_label": "samgovapi",
        "server_url": "https://samgovapi.io/api/mcp",
        "headers": {"Authorization": f"Bearer {os.environ['SAMGOVAPI_API_KEY']}"},
        "allowed_tools": ["registration_status", "exclusion_check", "search_opportunities"],
        "require_approval": "never",
    }],
    input="Is UEI ZXBCU6K5KL99 registered in SAM.gov, and when does its registration expire?",
)
print(resp.output_text)
```

2. Approvals: Leave require_approval at its default to get an mcp_approval_request item before each call, and answer it with an mcp_approval_response in the next request.

## Finish account setup once

Data tools unlock after the account answers its onboarding questions: ask the agent to set up your samgovapi account (get_onboarding_questions, then answer_onboarding). Free.

## Check that it works

Ask: "Is UEI ZXBCU6K5KL99 registered in SAM.gov, and when does its registration expire?"

Expected tool call:

```json
{"name":"registration_status","arguments":{"id":"ZXBCU6K5KL99","user_request":"check a registration and its expiry"}}
```

## Things to know

- The model name is an example; use any Responses model that supports remote MCP tools.

## Troubleshooting

- The response contains approval requests instead of answers: require_approval defaults to always. Set never, or approve each request.
- Tool errors mention INVALID_API_KEY: The headers field is missing or the variable is empty.
- ONBOARDING_REQUIRED: Answer the onboarding questions once for the account (get_onboarding_questions, answer_onboarding).

## Questions

### Does OpenAI see my key?

It is sent to OpenAI with the request so it can call the server; OpenAI documents that it is not stored or returned.

## Official documentation

- OpenAI: remote MCP servers and connectors: https://developers.openai.com/api/docs/guides/tools-connectors-mcp

Checked 2026-11-13. All guides: https://samgovapi.io/agents.md

Independent. Not affiliated with, endorsed by or sponsored by GSA, SAM.gov or any U.S. government agency. Registering in SAM.gov is free at sam.gov.
