> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Phaseo Gateway base URL: https://api.phaseo.app/v1. Send `Authorization: Bearer $PHASEO_API_KEY` with every request.
> Model IDs look like `provider/model`, for example `openai/gpt-6-astra`. Do not guess IDs: list them with `GET /v1/models` or check https://phaseo.app/models. `phaseo/free` routes to an available free model and needs no wallet balance.
> For new text integrations prefer `POST /v1/responses`. `POST /v1/chat/completions` (OpenAI format) and `POST /v1/messages` (Anthropic format) suit existing code.
> The full API contract is https://phaseo.app/docs/openapi/v1/openapi.yaml. Official SDKs: `@phaseo/sdk` (TypeScript) and `phaseo` (Python), plus Go, C#, PHP, Ruby and Rust.
> Search these docs over MCP at https://phaseo.app/docs/mcp, and install Phaseo skills with `npx skills add https://phaseo.app/docs`. If a page is wrong or out of date, report it with the MCP `submit_feedback` tool.
> Manage Phaseo accounts with the `phaseo` CLI (`npm install -g @phaseo/cli`, then `phaseo login` or `phaseo login --device-code`), the `/v1` Management API or the MCP server at `https://mcp.phaseo.app/mcp?access=manage`. Do not send users to the dashboard for account tasks. A person is still needed for sign-up, approving a sign-in, paying the first top-up on the checkout link that `phaseo credits add` returns when no card is saved, confirming each saved-card top-up from the emailed link, and account security (password, MFA, passkeys). Create API keys with `phaseo keys create --name <name> --json`; never guess one. Credit top-ups need `phaseo login --scopes billing:write` first. Task map: https://phaseo.app/docs/v1/developers/manage-from-an-agent.md.

# Build a Python Gateway CLI

> Use the Python quickstart sample as a full walkthrough for a Python-first CLI or backend integration.

Use this page when your first real Phaseo integration lives in Python and you want a practical starting point for a CLI, worker, or backend service.

**Goal:** Run Phaseo control and generation routes from a small Python command-line application.

**Outcome:** A dependency-light CLI you can adapt into a worker, script, or backend integration.

Build a **Python gateway CLI** around Phaseo routes.

You are building a Python-first CLI or backend integration for Phaseo Gateway.

&#x20; Create a small Python app that:
&#x20; \- reads PHASEO\_API\_KEY from the environment
&#x20; \- supports one control-route smoke mode
&#x20; \- supports one text-generation command
&#x20; \- keeps the implementation dependency-light

&#x20; Requirements:
&#x20; \- Prefer the Python standard library unless there is a strong reason not to.
&#x20; \- Keep the request payloads explicit.
&#x20; \- Print clear success and failure output.
&#x20; \- Include one or two useful commands instead of a huge general CLI.
&#x20; \- Add a short README with examples.

&#x20; Deliverables:
&#x20; \- Python app code
&#x20; \- simple usage commands
&#x20; \- .env.example or equivalent env documentation

&#x20; Verification:
&#x20; \- run the smoke path if possible
&#x20; \- run one successful generation path if possible
&#x20; \- report exactly what you verified and what remains unverified.

## Sample project

* GitHub: [examples/gateway-python-quickstart](https://github.com/phaseoteam/Phaseo/tree/main/examples/gateway-python-quickstart)
* Local repo path: `examples/gateway-python-quickstart`

## What this app does

* supports control routes like:
  * `GET /v1/health`
  * `GET /v1/models`
  * `GET /v1/providers`
* supports generation routes like:
  * `POST /v1/responses`
  * `POST /v1/chat/completions`
  * `POST /v1/embeddings`
  * and several additional endpoints

## Why this sample is useful

It gives you:

* a Python-first reference without third-party dependencies
* explicit request payloads and response handling
* a practical pattern for workers, scripts, and internal tools

## Prerequisites

* Python 3
* a Phaseo API key

## Run the sample

```bash theme={null}
cd examples/gateway-python-quickstart
cp .env.example .env.local
```

Set:

* `PHASEO_API_KEY`

Then try:

```bash theme={null}
python quickstart.py smoke
python quickstart.py responses --prompt "Return exactly: integration_ok"
python quickstart.py --help
```

## Check your work

* Smoke mode confirms that the API is reachable.
* The Responses command prints `integration_ok`.
* `--help` lists the supported commands without making a request.
* Authentication and API failures produce clear terminal errors.

## What to look at in the code

* how the environment is loaded
* how the CLI dispatches commands
* how different request payloads are built
* how async video and music routes are handled separately from one-shot text routes

## How to make it your own

* strip it down to only the endpoints your service needs
* keep one shared request helper instead of duplicating headers everywhere
* switch to the Python SDK later if you want a higher-level client

## Related guides

* [Mini app starter prompts](https://phaseo.app/docs/v1/cookbook/mini-app-starter-prompts.md)
* [Ship structured JSON from Python](https://phaseo.app/docs/v1/cookbook/sdk-python-presets-and-json.md)
* [Examples](https://phaseo.app/docs/v1/guides/examples.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.