Skip to main content
Turn the running gateway into an OpenAI-compatible and MCP endpoint so SDK clients and MCP tools reach the same live agents as chat users. One process, one agent state, three protocols. This is different from praisonai serve openai, which runs a separate standalone OpenAI-only process.

Quick Start

1

Enable in gateway.yaml

Add the api block to your gateway config:
2

Start with CLI flags

Enable the same surfaces from the command line:
3

Enable in Python

Pass constructor flags to the gateway:

How It Works

Each API request dispatches into the gateway’s own registered agents, sharing the same session store and admission gate as chat users.

Endpoints Exposed

Call the OpenAI surface with any standard client:

Token Usage

Every response reports real per-turn token counts from the agent’s LLM instance. Each surface reports usage in its own OpenAI-native shape: When an agent exposes no LLM metrics, usage falls back to zeros in the correct spec shape, so clients never need to special-case a missing block.

Streaming Usage

Opt in with stream_options.include_usage: true to receive a streamed usage chunk — the same contract OpenAI’s own API uses.
The usage-only chunk is emitted right before data: [DONE]. Without include_usage, the stream frames are unchanged and no extra chunk is sent.
Streaming is still buffered: content is delivered once the full turn completes, so time-to-first-content matches non-streaming. Only the trailing usage chunk is new — this is not incremental token streaming.

Configuration Options

The gateway.api block maps to the ApiConfig dataclass. Both surfaces are opt-in; when both are False (default), no extra routes are mounted. ApiConfig also exposes an enabled property (true if either surface is on), plus to_dict() and from_dict().
Full API surface

How Auth Works

Every API route is protected by the same gateway.auth_token as /info and /metrics. The /info endpoint advertises which surfaces are enabled in its api field, so clients can introspect a running gateway before connecting.

When to Use vs praisonai serve openai

Use the gateway api: block when you want SDK clients and MCP tools to share live agents and sessions with chat users. Use praisonai serve openai when you want a standalone, lightweight OpenAI-only process with no gateway state. See OpenAI-Compatible Server.

Best Practices

Leave openai: false and mcp: false (the defaults) unless a client needs them. Disabled surfaces mount no routes and leave the gateway unchanged.
Every /v1/* and /mcp route uses the same gateway.auth_token. Set a strong token when binding to any non-loopback interface.
Pass an OpenAI-Session or X-Session-Id header to reuse one agent session across calls. Without it, stateless callers get a fresh session per request.
GET /info returns an api field listing enabled surfaces, so tooling can confirm what a gateway exposes before dispatching.
Pass stream_options={"include_usage": True} when using stream=True if your client tracks cost per response. The extra chunk arrives right before [DONE] and carries real per-turn totals.
The gateway snapshots the agent’s per-turn token metrics in the same execution context that produced the reply, so a usage field returned to one caller cannot be corrupted by a concurrent turn on the same shared agent. No configuration required.

Gateway

Gateway architecture and YAML configuration

OpenAI-Compatible Server

Standalone OpenAI-only server process

MCP Integration

Model Context Protocol servers and clients

Gateway CLI

CLI commands for managing the gateway