Skip to main content
praisonai serve openai starts a FastAPI server that exposes OpenAI-compatible HTTP endpoints — point any existing OpenAI SDK code at it and it works as a drop-in replacement. The user points an OpenAI SDK client at the server; chat completions route to your PraisonAI agent.

Quick Start

1

Simple Usage

The server starts on http://localhost:8765 by default.
2

With Configuration


How It Works


Endpoints

All endpoints follow the OpenAI REST specification.
The same provider is reachable as a client-side endpoint type via praisonai endpoints invoke --type openai-compat. Valid endpoint names: chat_completions, completions, models, tools_invoke.

Streaming

Set stream=True to receive tokens via Server-Sent Events:
The stream ends with a data: [DONE] sentinel. Errors during streaming are also sent as SSE events:

Tool Invocation

/v1/tools/invoke is a PraisonAI extension that calls an agent tool by name. It requires --agents-url to point to a running agents server.
Start the agents server first:

Authentication

Pass --api-key to require authentication:
Clients must include the key as the Authorization header:

CLI Reference


Choosing Between serve openai and serve rag --openai-compat

For OpenAI-compatible RAG queries, use praisonai serve rag --openai-compat instead. See RAG CLI for details.

Error Shape

All errors follow the OpenAI error format:

Best Practices

Always pass --api-key when running on a public or shared network. The default configuration accepts unauthenticated requests.
The default 127.0.0.1 only accepts local connections. Use --host 0.0.0.0 to accept connections from other machines — always pair with --api-key.
The server passes model directly to the underlying LLM. Use LiteLLM-style model names (ollama/llama3, anthropic/claude-3-5-sonnet-20241022) to route to any provider.
Use praisonai serve unified when you need multiple protocol surfaces (MCP, A2A, agents) alongside the OpenAI-compat layer. Use serve openai for a lightweight standalone deployment that only exposes OpenAI endpoints.

Concurrency & streaming (PraisonAI #3771)

  • Non-blocking handlers. All four handlers — /v1/chat/completions, /v1/completions, /v1/models, /v1/tools/invoke — offload the underlying sync provider.invoke via asyncio.to_thread. A slow provider call on one request does not stall concurrent requests on the same server.
  • Simulated streaming is word-by-word. When the underlying provider doesn’t stream natively, the server splits the response by whitespace and emits one SSE data: frame per word (whitespace preserved). Previously it emitted one frame per character, which most OpenAI-SDK clients handle correctly but at multi-order-of-magnitude higher per-token overhead.
  • No configuration flag — the change is unconditional and backward-compatible for real OpenAI-SDK clients.

Serve Commands

All praisonai serve subcommands

Gateway

Unified gateway and control plane

RAG OpenAI Compat

OpenAI-compatible RAG server

LLM Endpoint Config

Configure LLM provider endpoints