Reference
Headers, objects, and conventions.
This page documents shared conventions across endpoints: HTTP headers, error envelopes, common object shapes, and compatibility notes.
HTTP headers
Required
Authorization: Bearer $LMCHAT_API_KEY
Content-Type: application/jsonRecommended
HTTP-Referer: https://yourapp.com
X-Title: YourAppName
# For safe retries (where supported):
Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000Error envelope
Shape
Errors follow an OpenAI-style envelope where possible.
{
"error": {
"message": "Human-readable message",
"type": "invalid_request_error | authentication_error | rate_limit_error | api_error",
"code": "machine_readable_code"
}
}Usage object
Tokens accounting
Usage reporting typically includes prompt, completion, and total tokens. Some providers may report additional fields; clients should ignore unknown properties.
"usage": {
"prompt_tokens": 123,
"completion_tokens": 45,
"total_tokens": 168
}Chat message object
Roles
Typical roles are system, user, assistant, and tool.
{
"role": "user",
"content": "Hello"
}Compatibility notes
- Most SDKs work by overriding baseURL and providing a key.
- Not all models support all features (tools, vision, JSON mode).
- Streaming uses SSE and ends with [DONE].
- Clients should be tolerant to additional fields and provider-specific metadata.