API & Integration Guide

APEX provides an OpenAI-compatible REST API. Third-party developer extensions, AI clients (Continue, Cline, Roo Code, Aider, Open WebUI), and official OpenAI SDKs connect directly without code alterations.

Base URL & Authentication

When APEX is online, the base URL is exposed through your Cloudflare Quick Tunnel:

Base URL: https://<subdomain>.trycloudflare.com/v1

Authentication Headers

When authentication is enabled (default), include your Bearer token in the Authorization header:

Authorization: Bearer YOUR_APEX_API_KEY

Note: Discovery endpoints (/health, /runtime, /version, /chat, and /) remain unauthenticated to allow health checking and browser landing access.

Python OpenAI SDK Example

APEX is fully compatible with the official openai Python package (v1.0.0+):

from openai import OpenAI

# Initialize client pointing to your APEX tunnel endpoint
client = OpenAI(
    base_url="https://<subdomain>.trycloudflare.com/v1",
    api_key="YOUR_APEX_API_KEY"
)

# Chat completion request with streaming
response = client.chat.completions.create(
    model="Qwen/Qwen2.5-1.5B",
    messages=[
        {"role": "system", "content": "You are a concise, helpful assistant."},
        {"role": "user", "content": "Explain quantum computing in two sentences."}
    ],
    temperature=0.7,
    max_tokens=256,
    stream=True
)

for chunk in response:
    content = chunk.choices[0].delta.content or ""
    print(content, end="", flush=True)
print()

cURL Example

curl -X POST "https://<subdomain>.trycloudflare.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_APEX_API_KEY" \
  -d '{
    "model": "Qwen/Qwen2.5-1.5B",
    "messages": [
      {"role": "user", "content": "Hello from cURL!"}
    ],
    "temperature": 0.7,
    "max_tokens": 128
  }'

Supported Endpoints

Method Endpoint Description Status
POST /v1/chat/completions OpenAI-compatible chat completion (streaming SSE & JSON). Verified
GET /v1/models Lists the active loaded model and available aliases. Verified
POST /v1/files Upload documents for text context extraction (.txt, .pdf, .docx, .csv, .json). Verified
GET /v1/files Lists uploaded files in the active workspace. Verified
GET /v1/files/{id} Retrieves extracted text and metadata for a specific document. Verified
DELETE /v1/files/{id} Deletes an uploaded document and removes its context. Verified
GET /health System uptime, queue status, GPU availability, and model readiness. Verified
GET /runtime Telemetry details: VRAM usage, engine type, active precision. Verified
GET /chat Built-in web chat application for browser interaction. Verified
POST /v1/completions Legacy text completion endpoint. Supported
POST /v1/embeddings Returns static dummy vectors (not a trained embedding model). Stub
POST /v1/images/* Image generation and editing endpoints. 501 Stub

Streaming Protocol (SSE)

When "stream": true is provided, APEX streams tokens using standard Server-Sent Events with the exact structure expected by OpenAI client libraries:

data: {"id":"chatcmpl-a1b2c3","object":"chat.completion.chunk","created":1730000000,"model":"Qwen/Qwen2.5-1.5B","choices":[{"index":0,"delta":{"content":"Quantum"},"finish_reason":null}]}

data: {"id":"chatcmpl-a1b2c3","object":"chat.completion.chunk","created":1730000000,"model":"Qwen/Qwen2.5-1.5B","choices":[{"index":0,"delta":{"content":" computing"},"finish_reason":null}]}

data: [DONE]