Download prompt

How do you call the Free AI API? Full reference

This page documents every endpoint of the free, keyless AI API. If you prefer not to read it, download the integration prompt and let your AI assistant write the code.

Base URL

https://api.apiaifree.com/v1

All requests use HTTPS. Request and response bodies are JSON in UTF-8, except for /ask, which returns plain text by default. Cross-origin requests are allowed from any website.

Authentication

There is none. The API has no keys, accounts or tokens. An Authorization header is accepted and ignored, so libraries that require a key work with any placeholder value such as free.

Chat completions

POST /v1/chat/completions is the main endpoint. It takes a conversation and returns the next assistant message.

Request parameters

FieldTypeDescription
messagesarray, requiredConversation so far. Each item has a role (system, user or assistant) and text content.
modelstringUse free-ai. Any other value is accepted and mapped to the same model.
max_tokensintegerMaximum length of the answer. Default 1024, maximum 8192.
temperaturenumberRandomness from 0 to 2. Lower values give more predictable text.
top_pnumberNucleus sampling threshold, an alternative to temperature.
stopstring or arraySequences at which generation stops.
seedintegerMakes sampling repeatable for the same input.
streambooleanReturn the answer as Server-Sent Events.
reasoningbooleanLet the model think before answering. See below.
response_formatobject{"type":"json_object"} asks for valid JSON output.

Example request

curl https://api.apiaifree.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "free-ai",
    "max_tokens": 300,
    "temperature": 0.7,
    "messages": [
      {"role": "system", "content": "You answer in one short paragraph."},
      {"role": "user", "content": "Why is the sky blue?"}
    ]
  }'

Example response

{
  "id": "chatcmpl-8vlcqzR9pSE5FVxh",
  "object": "chat.completion",
  "model": "free-ai",
  "choices": [{
    "index": 0,
    "finish_reason": "stop",
    "message": {"role": "assistant", "content": "Sunlight is scattered by air molecules…"}
  }],
  "usage": {"prompt_tokens": 74, "completion_tokens": 58, "total_tokens": 132}
}

The answer text is in choices[0].message.content. A finish_reason of length means the answer was cut by max_tokens.

Streaming

With "stream": true the response has the content type text/event-stream. Each event is a line starting with data: that carries a JSON chunk; the new text is in choices[0].delta.content. The stream ends with data: [DONE].

const res = await fetch("https://api.apiaifree.com/v1/chat/completions", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ model: "free-ai", stream: true,
    messages: [{ role: "user", content: "Tell me a short story." }] }),
});
const reader = res.body.getReader(), dec = new TextDecoder();
let buf = "";
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  buf += dec.decode(value, { stream: true });
  const lines = buf.split("\n"); buf = lines.pop();
  for (const line of lines) {
    if (!line.startsWith("data:") || line.includes("[DONE]")) continue;
    const text = JSON.parse(line.slice(5)).choices?.[0]?.delta?.content;
    if (text) process.stdout.write(text);
  }
}

Reasoning mode

By default the model answers straight away. Send "reasoning": true to let it work through the problem first. Thinking consumes output tokens, so set max_tokens to at least 2000; with a small limit the visible answer can come back empty. The thinking text is returned separately in choices[0].message.reasoning_content.

The /ask endpoint

GET /ask or POST /ask answers a single question and returns plain text. It exists for shell scripts, spreadsheets, webhooks and other places where building JSON is inconvenient.

ParameterDescription
qThe question, URL-encoded. Required.
systemOptional instructions for the model.
max_tokensOptional answer length, default 1024.
formatSet to json to receive {"answer": "…"} instead of text.
curl "https://api.apiaifree.com/ask?q=Give+me+a+synonym+for+fast"
curl "https://api.apiaifree.com/ask?q=Name+three+colors&format=json"

Text completions

POST /v1/completions continues a raw string passed in the prompt field, without chat roles. It accepts the same sampling parameters and returns the text in choices[0].text. Use it for autocomplete-style tasks; for everything else prefer chat completions.

Models and health

GET /v1/models returns a list with one entry, free-ai. GET /health returns {"status":"ok"} with status 200 when the model server is reachable, and status 503 when it is not. Poll it before long batch jobs.

Limits

LimitValue
Requests per day or per minuteNot limited
Parallel connections per IP address8
Request body1 MB
Input across all messages120,000 characters
Output per request8,192 tokens
Request timeout300 seconds
ModalitiesText in, text out

Errors and retries

Errors use the familiar shape {"error": {"message": "…", "type": "…", "code": 400}} together with a matching HTTP status.

StatusMeaningWhat to do
400Invalid JSON or missing messagesFix the request body
404Unknown endpointCheck the path
405Wrong HTTP methodUse POST for completions
413Body or input too largeShorten the conversation
429More than 8 parallel connectionsWait for a running request to finish
503Model busy or temporarily offlineRetry after 2–5 seconds, up to three times

A simple exponential backoff covers both 429 and 503. Set your HTTP client timeout to at least 120 seconds, because long answers take time to generate.

SDKs and tools

Any client that speaks the chat completions format can use the API by overriding the base URL.

Python SDK

from openai import OpenAI
client = OpenAI(base_url="https://api.apiaifree.com/v1", api_key="free")

JavaScript SDK

import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.apiaifree.com/v1", apiKey: "free" });

LangChain, n8n and other tools

Choose the “OpenAI-compatible” or “custom base URL” option, enter https://api.apiaifree.com/v1, type any text into the key field and set the model to free-ai.