OpenAI and Anthropic compatible
The LocAI API
Use familiar SDKs with the real LocAI endpoint. Keep your API key server-side, set the correct base URL, and call LocAI-Go.
Connection Settings
SDKs need a base URL. Raw HTTP clients need the complete endpoint path.
OpenAI-compatible
Base URL
https://api.locai.com.au/v1
Model
LocAI-GoAnthropic-compatible
Base URL
https://api.locai.com.au/anthropic
Model
LocAI-GoAuthentication
Authorization: Bearer
LCCM_<your_key>Implemented Endpoints
Only the public routes implemented by the LocAI Gateway are listed here.
OpenAI-compatible routes
POST /v1/chat/completions
GET /v1/models
Anthropic-compatible routes
POST /anthropic/v1/messages
GET /anthropic/v1/models
Working Examples
Replace the placeholder with a key created in your LocAI dashboard.
OpenAI SDK — Python
from openai import OpenAI
client = OpenAI(
api_key="LCCM_<your_key>",
base_url="https://api.locai.com.au/v1",
)
response = client.chat.completions.create(
model="LocAI-Go",
messages=[{"role": "user", "content": "Hello, LocAI!"}],
)
print(response.choices[0].message.content)OpenAI SDK — JavaScript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.LOCAI_API_KEY,
baseURL: "https://api.locai.com.au/v1",
});
const response = await client.chat.completions.create({
model: "LocAI-Go",
messages: [{ role: "user", content: "Hello, LocAI!" }],
});
console.log(response.choices[0].message.content);Raw HTTP — cURL
curl -X POST "https://api.locai.com.au/v1/chat/completions" \
-H "Authorization: Bearer LCCM_<your_key>" \
-H "Content-Type: application/json" \
-d '{
"model": "LocAI-Go",
"messages": [{"role": "user", "content": "Hello, LocAI!"}]
}'Anthropic SDK — Python
from anthropic import Anthropic
client = Anthropic(
api_key="LCCM_<your_key>",
base_url="https://api.locai.com.au/anthropic",
)
message = client.messages.create(
model="LocAI-Go",
max_tokens=512,
messages=[{"role": "user", "content": "Hello, LocAI!"}],
)
print(message.content[0].text)Managed Web Search
Enable bounded Gateway-managed search for requests that need current or verifiable information.
Headers
X-LocAI-Agent: managed
X-LocAI-Web-Search: autoModes
off disables managed search.auto searches when needed.required attempts one bounded search.
Build with the real LocAI API
Start with LocAI-Go and the exact connection settings above.
Read the Docs