AI API - PHP Edition

Multi-provider OpenAI-compatible REST API in pure PHP (built-in web server + cURL)

Base URL: http://localhost:3000

Overview

A pure-PHP OpenAI-compatible API gateway with zero dependencies. Serves the chat UI from public/ and exposes a standard /v1 API.

Model IDDisplay nameProvider
aibanglaBangla AIAIBanglaChat
muslimgptMuslimGPTMuslimGPT
myquranMyQuran AIMyQuran
aichattingAIChattingAIChatting.net
Compatibility: Text-only. Image input is rejected with a 400 image_not_supported error.

Install & Run

Requirements: PHP 8+ with the cURL and OpenSSL extensions enabled.

# 1. Copy the example config
cp .env.example .env

# 2. Boot the built-in PHP web server
php -S localhost:3000 index.php

Open http://localhost:3000 for the chat UI, or http://localhost:3000/docs.html for this page.

Authentication

Optional, controlled by API_KEY in .env.

# If API_KEY is set, include this header:
Authorization: Bearer your_secret_api_key

List Models

GET/v1/models

Lists all available model IDs.

{ "object": "list", "data": [{ "id": "aibangla", "object": "model", "created": 1788935057, "owned_by": "aibangla" }] }

Chat Completions

POST/v1/chat/completions

Generate completions using the selected model.

FieldTypeRequiredDescription
modelstringoptionalModel ID: aibangla, muslimgpt, myquran, aichatting.
messagesarrayyes{role, content} array.
streambooleanoptionaltrue for SSE streaming.

Example

curl -X POST http://localhost:3000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "muslimgpt",
    "messages": [{ "role": "user", "content": "Hello!" }],
    "stream": false
  }'

Streaming (SSE)

Set stream: true to receive Server-Sent Events ending with [DONE].

data: {"id":"chatcmpl-x","object":"chat.completion.chunk","created":1788,"model":"muslimgpt","choices":[{"index":0,"delta":{"content":"Peace "},"finish_reason":null}]}

data: {"id":"chatcmpl-x","object":"chat.completion.chunk","created":1788,"model":"muslimgpt","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Use with opencode

Configuration for opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "local-ai": {
      "api": "openai",
      "name": "Local AI Gateway",
      "options": {
        "apiKey": "dummy",
        "baseURL": "http://localhost:3000/v1"
      },
      "models": {
        "aibangla":   { "id": "aibangla",   "name": "Bangla AI",   "tool_call": false, "reasoning": false },
        "muslimgpt":  { "id": "muslimgpt",  "name": "MuslimGPT",  "tool_call": false, "reasoning": false },
        "myquran":    { "id": "myquran",    "name": "MyQuran AI", "tool_call": false, "reasoning": false },
        "aichatting": { "id": "aichatting", "name": "AIChatting", "tool_call": false, "reasoning": false }
      }
    }
  },
  "model": "local-ai/aibangla"
}

Errors

{ "error": { "message": "Description of error" } }