Skip to main content

When to Use OpenAI-Compatible Endpoint

The OpenAI-compatible API is ideal when:
  • You’re migrating from OpenAI and want minimal code changes
  • You’re using frameworks built for OpenAI (LangChain, LlamaIndex, Vercel AI SDK)
  • You want a simple chat interface for browser automation
  • You need streaming responses
  • You prefer the familiar OpenAI SDK patterns
Choose native REST/WebSocket instead if you need:
  • Multi-task sessions with persistent browser state
  • Manual browser control and takeover
  • Video streaming
  • Fine-grained session management
The OpenAI-compatible endpoint creates a new session for each request and auto-terminates after completion. For multi-task workflows, use the native REST API.

Setup with OpenAI SDK

Installation

Basic Usage

Response:

Framework Examples

LangChain

With Streaming:
With Chains:

LlamaIndex

With Agent:

Vercel AI SDK

With Streaming:
In Next.js Route Handler:

Chat Completions Format

Request Format

Parameters:

Non-Streaming Response


Streaming Response

When stream: true, responses use Server-Sent Events (SSE):
Handling Streams:

Available Models

Currently, only webrun-browser-1 is available. Additional models may be added in the future.

Differences from Standard OpenAI API

Supported Features

  • Chat completions endpoint
  • Streaming responses
  • Message history
  • System messages
  • Token usage reporting

Not Supported

  • Function calling (use native REST API for manual control)
  • Vision (images in messages)
  • Tool use (use native REST API for multi-task workflows)
  • Fine-tuning
  • Embeddings
  • Moderation
  • Audio/Speech
  • Temperature/top_p (task execution is deterministic)

Different Behavior

1. Session Management
  • OpenAI: Stateless, each request is independent
  • WebRun: Each request creates a new browser session that auto-terminates
2. Response Time
  • OpenAI: Typically 1-5 seconds
  • WebRun: Typically 10-50 seconds (real browser automation)
3. Context Window
  • OpenAI: Based on model (e.g., 128k tokens)
  • WebRun: Task-focused, less emphasis on large context
4. Pricing
  • OpenAI: Per-token pricing
  • WebRun: Per-task pricing with token usage included in response

Limitations

Multi-Task Workflows

The OpenAI-compatible endpoint creates a new session per request. For multi-step workflows, use the native REST API:

Guardrails

Guardrails (human-in-the-loop) are not supported via OpenAI-compatible endpoint. If a guardrail triggers, the request will fail:
Solution: Use native REST or WebSocket API for guardrail handling.

Video Streaming

Live video streaming is not available via OpenAI-compatible endpoint. Use native REST API to get webRTCURL and webViewURL.

Complete Example: Research Assistant


Error Handling