docs/openai-api.md
nanobot can expose a minimal OpenAI-compatible endpoint for local integrations:
pip install "nanobot-ai[api]"
nanobot serve
By default, the API binds to 127.0.0.1:8900. You can change this in config.json.
"session_id" in the request body to isolate conversations; omit for a shared default session (api:default)user messagemodel, or pass the same model shown by /v1/modelsstream=true to receive Server-Sent Events (text/event-stream) with OpenAI-compatible delta chunks, terminated by data: [DONE]; omit or set stream=false for a single JSON responsemultipart/form-data (max 10MB per file)api channel, so the message tool does not automatically deliver to Telegram/Discord/etc. To proactively send to another chat, call message with an explicit channel and chat_id for an enabled channel.Example tool call for cross-channel delivery from an API session:
{
"content": "Build finished successfully.",
"channel": "telegram",
"chat_id": "123456789"
}
If channel points to a channel that is not enabled in your config, nanobot will queue the outbound event but no platform delivery will occur.
GET /healthGET /v1/modelsPOST /v1/chat/completionscurl http://127.0.0.1:8900/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "hi"}],
"session_id": "my-session"
}'
Send images inline using the OpenAI multimodal content format:
curl http://127.0.0.1:8900/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Describe this image"},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBOR..."}}
]}]
}'
Upload any supported file type (images, PDF, Word, Excel, PPT) via multipart:
# Single file
curl http://127.0.0.1:8900/v1/chat/completions \
-F "message=Summarize this report" \
-F "[email protected]"
# Multiple files with session isolation
curl http://127.0.0.1:8900/v1/chat/completions \
-F "message=Compare these files" \
-F "[email protected]" \
-F "[email protected]" \
-F "session_id=my-session"
Supported file types:
requests)import requests
resp = requests.post(
"http://127.0.0.1:8900/v1/chat/completions",
json={
"messages": [{"role": "user", "content": "hi"}],
"session_id": "my-session", # optional: isolate conversation
},
timeout=120,
)
resp.raise_for_status()
print(resp.json()["choices"][0]["message"]["content"])
openai)from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:8900/v1",
api_key="dummy",
)
resp = client.chat.completions.create(
model="MiniMax-M2.7",
messages=[{"role": "user", "content": "hi"}],
extra_body={"session_id": "my-session"}, # optional: isolate conversation
)
print(resp.choices[0].message.content)