§ 00Integrations · OpenAI Agents API

OpenAI Agents API quickstart: a server that keeps its files and a live URL

The OpenAI Agents API can call any remote MCP server. Point an agent at Server4Agent and it gets a server of its own: a project that keeps its files from one session to the next, and a deploy tool that puts what it built at a live URL. Nothing to install on our side, just an API key.

§ 01Quickstart

One script, from agent to live URL

It creates a session whose agent has the Server4Agent tools and asks for a page to be built and deployed. The agent replies with the URL.

  • ▸An OpenAI API key with the api.agents.read, api.agents.write and api.responses.write scopes. OpenAI bills the agent's tokens.
  • ▸A Server4Agent account and an API key from the API Keys page. The free plan is enough for this example.
  • ▸Python and the openai package, upgraded to a version with the Agents API.
quickstart.py
"""OpenAI Agents API + Server4Agent over MCP.

Gives an OpenAI managed agent the Server4Agent MCP server, then asks it to
build a page and put it online. The agent writes the files into a Server4Agent
project and deploys it, so the result has a live URL and is still there for
the next session.

Run:
    pip install --upgrade openai
    export OPENAI_API_KEY=...           # with api.agents.read, api.agents.write, api.responses.write
    export S4A_API_KEY=sk_live_...      # server4agent.com, API Keys
    python quickstart.py

Config follows OpenAI's Agents API quickstart and MCP connections docs:
https://developers.openai.com/api/docs/guides/agents-api/quickstart
https://developers.openai.com/api/docs/guides/agents-api/tools/mcp
"""

import os

from openai import OpenAI

S4A_MCP_URL = "https://mcp.server4agent.com"

TASK = (
    "Use Server4Agent to put a one-page site online: a page that says hello "
    "and shows today's date. Reuse a running server if one has room, create a "
    "project, write the files, start the app, deploy it, and reply with the URL."
)

# Every Server4Agent tool except the ones that remove things, so nothing the
# agent does can delete a server, project, file, secret or domain, and the
# ones that connect an agent's own sandbox to a project. Add a tool name here
# when you need it.
ALLOWED_TOOLS = [
    "list_servers", "get_server", "create_server", "update_server", "control_server", "get_usage",
    "list_projects", "get_project", "list_templates", "create_project", "update_project",
    "init_project", "export_project", "import_project", "deploy",
    "list_files", "read_file", "write_file", "get_download_url",
    "exec", "start_app", "prompt", "start_build", "get_build", "get_run", "get_logs",
    "set_secret", "list_secrets", "attach_secret",
    "add_domain", "check_domain",
]

server4agent = {
    "type": "mcp",
    "server_label": "server4agent",
    "transport": {
        "type": "http",
        "server_url": S4A_MCP_URL,
        # Server4Agent reads the key from X-API-Key as well as Authorization.
        "headers": {"X-API-Key": os.environ["S4A_API_KEY"]},
    },
    "allowed_tools": ALLOWED_TOOLS,
    "required": True,  # fail the turn if the server cannot be reached
}

client = OpenAI()  # reads OPENAI_API_KEY

stream = client.beta.agents.sessions.create(
    agent={
        "model": "gpt-6-astra",
        "instructions": (
            "You build and host things with the Server4Agent tools. Projects "
            "are private until you deploy them. Always reply with the live URL."
        ),
        "tools": [server4agent],
    },
    # Server4Agent is where the files live and the app runs, so this agent
    # needs no sandbox of its own.
    environment={"type": "none"},
    input=TASK,
    stream=True,
)

result = stream.get_final_result()
print(result.output_text)
print(f"\nSession {result.session_id}")
terminal
pip install --upgrade openai
export OPENAI_API_KEY=...           # needs api.agents.read, api.agents.write, api.responses.write
export S4A_API_KEY=sk_live_...      # from Server4Agent, API Keys
python quickstart.py

The model is the one OpenAI’s quickstart uses; swap in any model your key can call. Everything the agent builds is a real project on your account, private until it deploys.

§ 02The config

What each part does

Every field is from OpenAI's docs as of November 24, 2026. The server URL is the only Server4Agent setting.

An mcp tool on the agent

A tool of type mcp with an http transport whose server_url is https://mcp.server4agent.com. server_label is the name the agent sees the tools under.

The key in a header

The transport sends your Server4Agent API key in an X-API-Key header, which Server4Agent reads as well as Authorization. OpenAI encrypts inline headers and leaves them out of the session it returns.

allowed_tools and required

allowed_tools lists every Server4Agent tool except the ones that remove things, so the agent cannot delete a server, project, file, secret or domain, and the ones that connect an agent's own sandbox to a project, which a builder has no use for. required makes the turn fail if the server cannot be reached, rather than carry on without it.

No sandbox needed

environment type none runs the agent without a sandbox. OpenAI's harness calls remote MCP tools directly, and the files and running app live in your Server4Agent project. Use openai_hosted instead if you also want OpenAI's own shell.

§ 03Next session

A fresh session finds the same project

The Server4Agent project outlives the session that made it, at the same URL, so a later session can pick the work up where the last one left it.

next_session.py
stream = client.beta.agents.sessions.create(
    agent={"model": "gpt-6-astra", "tools": [server4agent]},
    environment={"type": "none"},
    input=(
        "Open the Server4Agent project you deployed yesterday, add a contact "
        "section, and deploy it again. Keep the same URL."
    ),
    stream=True,
)
print(stream.get_final_result().output_text)
§ 04FAQ

Good to know

Why connect an OpenAI managed agent to Server4Agent?

An OpenAI-hosted sandbox gives each session its own workspace, and deletes it after an hour without keep-alives. Through Server4Agent the agent writes into a project on a server in your account: the files are still there next session, and a deploy puts the result at a live URL that stays up after the session ends.

Where does the MCP connection come from?

From OpenAI's service by default (connection_origin service), so the server must be reachable on the public internet, which mcp.server4agent.com is. Set connection_origin to environment only if the call should leave from your own sandbox, and note that connection then skips vault credentials.

Can I use a vault instead of an inline key?

Yes, for connections from OpenAI's service. Store the key as a vault credential for the server URL, pass vault_ids when you create the session, and drop the header. Send Authorization from one place only: inline or the vault, not both.

Will the agent ask before it acts?

With review left out, sessions run without sending MCP calls to your app for approval. Set review to auto_review on the session to have a reviewer model approve or deny calls that need confirmation, and keep the removal tools out of allowed_tools.

Can I limit what the key reaches?

Yes. A Server4Agent API key can be scoped to particular servers or projects, so an agent working for one customer cannot see another's. The account's monthly budget cap applies to every key, and the agent cannot raise it.

Who pays for what?

OpenAI bills the model tokens and any hosted sandbox. Server4Agent bills the servers and anything its own build agent does, within your plan. A session's spend_control can cap the OpenAI side.

§ 05Sources

OpenAI's docs this follows

Read on November 24, 2026. The Agents API is in beta, so check them if a field has moved.

Building on Claude instead? Follow the Claude Managed Agents quickstart. Deploying from the ChatGPT app rather than the API? Use the ChatGPT guide.