Skip to main content
The agent-server exposes an OpenAI-compatible /v1/chat/completions endpoint so clients that already speak the OpenAI protocol can call an OpenHands agent. Use this when you want an existing chat UI, IDE integration, evaluation harness, voice platform, or another agent to treat OpenHands as an OpenAI-style backend while still getting the full agent runtime behind the request.

What to Configure

Most OpenAI-compatible clients ask for the same three fields: For example, a saved LLM profile named gateway_demo appears as the OpenAI model openhands_gateway_demo. The gateway accepts the same session key in either OpenHands or OpenAI-compatible form:
  • X-Session-API-Key: <key>
  • Authorization: Bearer <key>

Prepare a Profile

OpenAI-compatible traffic is backed by an agent-server LLM profile. Create one with the native profile API first:
Then confirm the profile is visible to OpenAI clients:

Client Recipes

The response includes X-OpenHands-ServerConversation-ID. Save that header if you want a later request to continue the same agent conversation.

Conversation State

The OpenAI Chat Completions protocol usually sends full message history on every request. The OpenHands gateway does not reconstruct agent history from prior assistant messages. Instead:
  • Omit X-OpenHands-ServerConversation-ID to start a new OpenHands conversation.
  • Read X-OpenHands-ServerConversation-ID from the response.
  • Send that header on follow-up requests to continue the same OpenHands conversation.
When reusing a conversation, send the newest user turn in messages. The server-side OpenHands conversation owns the previous agent state, tool activity, and workspace context.

Current Limitations

  • Only non-streaming Chat Completions requests are supported. Requests with stream: true return 400 until streaming support is added.
  • The response contains the final assistant text only. Internal OpenHands tool activity is not exposed as OpenAI tool calls.
  • OpenAI request fields that are not needed by the gateway are ignored or rejected intentionally by the server implementation.

Ready-to-run example

examples/02_remote_agent_server/15_openai_compatible_gateway.py
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o). The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.