Documentation/Integration guide/Chat completions
Integration guide

Chat completions

OpenAI-compatible chat completion endpoints for dynamic character dialogue and lore generation.

4 min read
•Updated October 21, 2026

OpenAI-Compatible Chat Endpoint

POST /v1/chat/completions accepts model=persona-v1, messages, temperature and optional max_tokens. This is a non-streaming JSON endpoint.

Provider Routing & Service Availability

A real text provider must be configured by the operator. If none is configured, the route returns 503 before reserving credits. A catalog entry alone is not proof the model is available.

Token Metrics & Internal Isolation

Responses contain choices and usage supplied by the provider. Token counts must not be inferred from word counts. No client should depend on an internal provider model name.

Code Implementation

import os
import time
import requests

BASE = "https://api.apimarketplace.com"
headers = {"Authorization": "Bearer " + os.environ["API_KEY"]}

def call(method, path, **kwargs):
    response = requests.request(method, BASE + path, headers=headers, timeout=300, **kwargs)
    response.raise_for_status()
    return response.json() if response.content else None

def wait(path, success):
    deadline = time.monotonic() + 900
    while time.monotonic() < deadline:
        result = call("GET", path)
        if result["status"] == success:
            return result
        if result["status"] == "failed":
            raise RuntimeError(result.get("errorMessage") or "Generation failed")
        time.sleep(3)
    raise TimeoutError("Still pending; keep the returned ID and check later")

payload = {'model': 'persona-v1',
 'messages': [{'role': 'user',
               'content': 'Write a brief character biography.'}],
 'temperature': 0.7,
 'max_tokens': 512}
result = call('POST', '/v1/chat/completions', json=payload)
print(result)