Skip to main content
Use the Python Agents SDK’s native Streamable HTTP client with Magic Hour’s hosted MCP. The walkthrough below discovers tools, checks Magic Hour authorization, and retrieves an existing image. It calls no model and needs no OpenAI API key.

Install and configure

Requires Python 3.10+. Install the SDK and MCP versions verified together:
Provide a Magic Hour API key through your secret manager as MAGIC_HOUR_API_KEY. Set MAGIC_HOUR_IMAGE_PROJECT_ID to an image project ID already saved from an accepted generation. Keep keys, account details, and temporary download URLs private.

Verify access and recover an image

Save this as your application entry point and run it with Python. It disables SDK tracing and closes the MCP connection when the async with block exits.
Discovery alone does not prove API authorization; account_retrieve checks the key. This example does not print the private account response. Reusing the same project ID reads the accepted job without submitting or charging for a new generation. A timeout does not cancel the job: keep its ID and retry recovery. This example limits inline media to 1 MiB; use the exact returned signed download URL when an output cannot be embedded, preserving its query parameters.

Use with an agent

Pass the connected server to an Agents SDK agent through mcp_servers=[server] while its context remains open. Native validation confirmed tool discovery, authenticated account access, same-ID recovery, inline PNG retrieval, context teardown, and conversion of 48 tools through Agent.get_mcp_tools. No Runner or model was invoked. Model-backed runs require their own provider configuration and can spend provider tokens as well as Magic Hour credits when generation tools are called. Generation sends authorized prompts and media to Magic Hour and spends credits. Persist every accepted project ID before waiting; recover it instead of repeating a paid creation. See Magic Hour MCP for uploads, generation, and download rules, our privacy policy, and the official SDK transport source.