Free API Docs v1.0.0
API Online
Playground
API Reference / Overview

Free API Developer Reference

High-speed AI reasoning API gateway supporting OpenAI SDK drop-in compatibility, standard REST JSON completions, and sub-second Server-Sent Events (SSE) token streaming.

Base URL & Authentication

By default, the server is hosted locally at port 8000 or your deployment domain.

Interface Base URL Authentication
Native REST Endpoints https://freeapi.space None required.
OpenAI SDK Endpoint https://freeapi.space/v1 Accepts any placeholder string (e.g. api_key="free-api-key").
Headers: Send Content-Type: application/json on all POST requests. To consume streaming endpoints via standard HTTP clients, set Accept: text/event-stream.

Quickstart

Send your first query to the native endpoint using cURL, Python, or JavaScript:

curl -X POST "https://freeapi.space/api/chat" \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Explain the halting problem concisely."}'

OpenAI SDK Compatibility

The server provides complete drop-in compatibility with official OpenAI SDKs, LangChain, LiteLLM, and LlamaIndex. Point your client to base_url="https://freeapi.space/v1".

from openai import OpenAI

client = OpenAI(
    base_url="https://freeapi.space/v1",
    api_key="free-api-key"  # Any non-empty string is accepted
)

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are an expert tutor."},
        {"role": "user", "content": "Explain Dijkstra's algorithm."}
    ],
    stream=True
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()
POST /v1/chat/completions

Creates a model completion for the chat message history. Supports both standard JSON payloads and real-time SSE chunk streams. Also accessible via alias POST /chat/completions.

Request Body
Parameter Type Required Description
messages array Optional List of message objects: [{"role": "user"|"system"|"assistant", "content": "..."}].
model string Optional Model identifier. Defaults to "gpt-4o".
stream boolean Optional If set to true, partial message deltas will be sent as Server-Sent Events. Defaults to false.
prompt string Optional Direct prompt string (alternative to message arrays).
Request Example
JSON PAYLOAD
{
  "model": "gpt-4o",
  "messages": [
    {"role": "system", "content": "You are an expert tutor."},
    {"role": "user", "content": "Explain binary search."}
  ],
  "stream": false
}
Response (200 OK — JSON Mode)
HTTP 200 OK
{
  "id": "chatcmpl-3a9f0e1b2c4d5e6f7a8b9c0d",
  "object": "chat.completion",
  "created": 1724370000,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Binary search is an efficient algorithm for finding an item from a sorted list of items..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 64,
    "total_tokens": 76
  }
}
GET /

Returns the API service name, operational status, and endpoint directory for automated client discovery.

Response (200 OK)
HTTP 200 OK
{
  "service": "Free API",
  "status": "online",
  "openai_compatible": true,
  "endpoints": {
    "openai_chat": "POST /v1/chat/completions",
    "chat": "POST /api/chat",
    "stream": "POST /api/chat/stream",
    "status": "GET /api/status",
    "docs": "GET /docs",
    "playground": "GET /playground"
  }
}
GET /api/status

Retrieves the browser worker health status.

Response Schema
Field Type Description
status string Health state of the server (e.g. "healthy").
Response Example
HTTP 200 OK
{
  "status": "healthy"
}
POST /api/chat

Executes an AI generation task. Returns the complete response object. If stream: true is specified, seamlessly delegates to the SSE streaming pipe.

Request Body
Parameter Type Required Description
prompt string Optional The question or prompt to send. If omitted, a question is selected randomly from the problem pool.
stream boolean Optional When true, delivers tokens via SSE stream. Defaults to false.
Response (200 OK — JSON Mode)
HTTP 200 OK
{
  "id": "msg_1787403401",
  "timestamp": "2026-08-23 00:30:15",
  "user_prompt": "Design an algorithm to find the median of two sorted arrays.",
  "ai_response": "To find the median in O(log(min(n,m))) time, we perform a binary search on the partition..."
}
Test Endpoint: POST /api/chat
Response
POST /api/chat/stream

Dedicated SSE streaming endpoint emitting chunks with mime-type text/event-stream. Each chunk provides the newly generated text delta, cumulative output, and completion status.

Wire Format Example
TEXT/EVENT-STREAM
data: {"delta": "Binary ", "full_text": "Binary ", "done": false}

data: {"delta": "search works ", "full_text": "Binary search works ", "done": false}

data: {"delta": "by halving the interval.", "full_text": "Binary search works by halving the interval.", "done": false}

data: {"delta": "", "full_text": "...", "done": true, "id": "msg_1787403402"}

data: [DONE]

SSE Streaming Protocol

The server sends Server-Sent Events with standard data: line prefixes, terminating with data: [DONE].

Event Stage JSON Payload Behavior
OpenAI Delta Chunk {"object": "chat.completion.chunk", "choices": [{"delta": {"content": "..."}}]} Emitted per token when using /v1/chat/completions with stream=true.
Native Stream Chunk {"delta": "...", "full_text": "...", "done": false} Emitted by /api/chat/stream and /api/chat.
Native Done Chunk {"done": true, "id": "...", "full_text": "..."} Sent upon generation completion with final status and message ID.
Termination data: [DONE] Signals the client to close the SSE connection.

Error Codes & Handling

Standard HTTP status codes are used to communicate success or error states:

Status Code Condition Example Body
200 OK Request processed successfully. {"status": "healthy", ...}
422 Unprocessable Request body failed schema validation. {"detail": [{"loc": ["body", "stream"], "msg": "value is not a valid boolean"}]}
500 Server Error Browser worker or session failure. {"detail": "Failed to retrieve AI response."}
ESC