API Documentation
Chat Completions
OpenAI-compatible chat/completions interface with persistent context, automatic learning options, scoped prompt resolution, and multi-provider key forwarding.
POST /api/v1/chat/completions
Proxy for OpenAI and Anthropic Chat APIs with automatic history prepending and system prompt injection. Supports GPT-4, Claude, and other models.
Scope: chat:write
Request
curl -X POST "https://www.mnexium.com/api/v1/chat/completions" \
-H "x-mnexium-key: $MNX_KEY" \
-H "Content-Type: application/json" \
-H "x-openai-key: $OPENAI_KEY" \
-d '{
"model": "gpt-4o-mini",
"messages": [\
{ "role": "user", "content": "I just switched to VS Code. Can you update my setup recommendations?" }\
],
"mnx": {
"subject_id": "user_123",
"chat_id": "550e8400-e29b-41d4-a716-446655440000",
"log": true,
"learn": true,
"recall": true,
"history": true
}
}'```
### mnx Parameters
| Parameter | Type | Description |
|----------------|----------|-------------------------------------------------------|
| `subject_id` | string | User/subject identifier for memory and history. |
| `chat_id` | string | Conversation ID (UUID recommended) for history grouping. |
| `log` | boolean | Save to chat history. Default: true |
| `learn` | boolean | Memory extraction: false (never), true (LLM decides), "force" (always). Default: true |
| `history` | boolean | Prepend chat history. Default: true |
| `system_prompt`| string | Prompt ID, true (auto-resolve), or false (skip). Default: true |
| `memory_policy`| string | Memory policy ID, false (skip), or omitted/true (auto-resolve). Default: true |
### Response
```json
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1702847400,
"model": "gpt-4o-mini",
"choices": [\
{\
"index": 0,\
"message": {\
"role": "assistant",\
"content": "Great choice! Since you work with Rust and Python, I'd recommend installing rust-analyzer and...",\
},\
"finish_reason": "stop"\
}\
],
"usage": { "prompt_tokens": 10, "completion_tokens": 12, "total_tokens": 22 }
}
Response headers include X-Mnx-Chat-Id and X-Mnx-Subject-Id
Set Streaming Example
Set "stream": true to receive Server-Sent Events (SSE).
Request for Streaming
curl -X POST "https://www.mnexium.com/api/v1/chat/completions" \
-H "x-mnexium-key: $MNX_KEY" \
-H "Content-Type: application/json" \
-H "x-openai-key: $OPENAI_KEY" \
-d '{ "model": "gpt-4o-mini", "messages": [{"role":"user","content":"What were we discussing last time?"}], "mnx": { "subject_id": "user_123", "history": true }, "stream": true }'
Response (SSE)
data: {"choices":[{"delta":{"role":"assistant"},"index":0}]}
data: {"choices":[{"delta":{"content":"Last"},"index":0}]}
data: {"choices":[{"delta":{"content":" time"},"index":0}]}
data: {"choices":[{"delta":{"content":" we"},"index":0}]}
data: {"choices":[{"delta":{"content":" talked"},"index":0}]}
data: {"choices":[{"delta":{"content":" about"},"index":0}]}
data: {"choices":[{"delta":{"content":" your Rust project..."},"index":0}]}
data: {"choices":[{"delta":{},"finish_reason":"stop","index":0}]}
data: [DONE]
Parse each data: line as JSON. Concatenate delta.content values to build the response.