Warning: Undefined variable $base in /var/www/belajarlinux/docs.php on line 17
API Documentation · Rumah AI
Developer

API Documentation

Gateway OpenAI-compatible. Ganti base URL dan API key — kode Anda yang sudah ada langsung jalan.

Quickstart

1. Daftar & buat API key di dashboard.
2. Kirim request ke /v1/chat/completions.
3. Selesai — usage, kredit, dan monitoring tercatat otomatis.

POST/v1/chat/completions

Autentikasi

Gunakan header Authorization: Bearer <KEY_ID>:<SECRET>. Key ID dan secret diberikan satu kali saat pembuatan.

HTTP HEADERS
Authorization: Bearer rai_live_xxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json

Chat Completions

Request

JSON — REQUEST
{
  "model": "oa/gpt-5.6",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Hello" }
  ],
  "temperature": 0.7,
  "max_tokens": 1024
}

Response

JSON — RESPONSE
{
  "id": "chatcmpl_...",
  "model": "oa/gpt-5.6",
  "choices": [
    { "message": { "role": "assistant", "content": "Hello! How can I help?" } }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 50,
    "total_tokens": 70,
    "credits_charged": 0.0012,
    "balance_remaining": 24.9988
  },
  "provider_used": "openai"
}

List Models

GET/v1/models
BASH
curl /v1/models \
  -H "Authorization: Bearer rai_live_xxxxxxxxxxxxxxxxxxxxxxxx"

Error Handling

JSON — ERROR
{
  "error": {
    "message": "Rate limit exceeded. Try again later.",
    "type": "rate_limited",
    "code": "rate_limited"
  }
}
CodeArtiAksi
401API key tidak valid / expiredPeriksa key
402Kredit tidak cukupTop up kredit
403IP tidak whitelist / model premiumAtur whitelist / upgrade plan
429Rate limit / quota habisLihat header Retry-After
502Provider gagal (fallback habis)Coba lagi / cek monitoring

cURL

BASH
curl /v1/chat/completions \
  -H "Authorization: Bearer rai_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "oa/gpt-5.6",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ]
  }'

Python

PYTHON
import requests

url = "/v1/chat/completions"
headers = {
    "Authorization": "Bearer rai_live_xxxxxxxxxxxxxxxxxxxxxxxx",
    "Content-Type": "application/json",
}
data = {
    "model": "oa/gpt-5.6",
    "messages": [{"role": "user", "content": "Hello!"}],
}
res = requests.post(url, json=data, headers=headers)
print(res.json()["choices"][0]["message"]["content"])

JavaScript

JAVASCRIPT
const res = await fetch("/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer rai_live_xxxxxxxxxxxxxxxxxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "oa/gpt-5.6",
    messages: [{ role: "user", content: "Hello!" }],
  }),
});
const data = await res.json();
console.log(data.choices[0].message.content);

PHP

PHP
<?php
$ch = curl_init('/v1/chat/completions');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer rai_live_xxxxxxxxxxxxxxxxxxxxxxxx',
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'oa/gpt-5.6',
        'messages' => [['role' => 'user', 'content' => 'Hello!']],
    ]),
]);
$res = json_decode(curl_exec($ch), true);
echo $res['choices'][0]['message']['content'];

Node.js (SDK OpenAI)

NODE.JS
const OpenAI = require('openai');

const client = new OpenAI({
  baseURL: '/v1',
  apiKey: 'rai_live_xxxxxxxxxxxxxxxxxxxxxxxx',
});

const res = await client.chat.completions.create({
  model: 'oa/gpt-5.6',
  messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(res.choices[0].message.content);