Overview
The Chat Completions API is fully compatible with OpenAI’s API format, allowing you to use the OpenAI Python SDK, JavaScript SDK, or any OpenAI-compatible client.Model Parameter (Optional): The
model parameter is optional and primarily for SDK compatibility. Your organization’s orchestrator agent automatically uses the configured LLM model.If you’re using an OpenAI SDK that requires the model parameter, you can pass any value (e.g., "junis-orchestrator") for compatibility.Prerequisites
Endpoint
Authentication
Include your API key in theX-API-Key header:
orchestrator:invoke
See Authentication for details.
Request Format
Basic Request
cURL
Request Parameters
Delegation (
on_behalf_of) is designed for partner services that provision
end-user accounts via User Provisioning.
Pending members are allowed so provisioned users work before their first login.Message Format
Messages follow the OpenAI format:system: System instructions (optional, rarely needed with Junis)user: User messagesassistant: Assistant responses (for conversation context)tool: Tool call results (for function calling)
Response Format
Non-Streaming Response
Status Code:200 OK
Response Body:
Response Fields
Streaming Mode
Enable real-time token-by-token streaming withstream: true.
Streaming Request
cURL
Streaming Response Format
Server-Sent Events (SSE) format:- Each line starts with
data: - First chunk contains
role - Subsequent chunks contain
contentdeltas - Final chunk has
finish_reason - Every chunk includes
session_idfor conversation continuity - Stream ends with
data: [DONE]
Multi-Agent Events
For Advanced Integrations: Junis streams additional agent lifecycle events alongside standard OpenAI chunks. These events have no
choices field, so standard OpenAI SDKs automatically ignore them - ensuring 100% backward compatibility.Parse these events to build rich UIs that show which agents are processing your request.Event Types
SSE Stream Example (Multi-Agent)
Parsing Agent Events (Python)
Parallel Agent Support
When multiple agents run concurrently (Parallel Agent), usetoken_agent events to correctly attribute tokens:
Session Management
Junis supports explicit session management viasession_id parameter, allowing you to control conversation context precisely.
How Sessions Work
Session ID Usage
Behavior:Example: Continuing a Conversation
Viewing Sessions
Retrieve your sessions via the Sessions API:Function Calling (Tool Use)
When a supported keyword is detected in the assistant’s response, the API returns atool_calls object with finish_reason: "tool_calls".
Error Handling
Common Errors
Error Types
Best Practices
- Use Streaming: Enable
stream: truefor long responses to provide real-time feedback - Handle Rate Limits: Implement exponential backoff when hitting rate limits (see error codes above)
- Keep Message History Concise: Trim old messages to avoid token limits (keep last 10-20 messages)
- Secure API Keys: Never hardcode API keys; use environment variables
- Log Requests: Log requests and responses for debugging and monitoring
Response Parameters
Temperature Guide
Next Steps
Sessions API
Retrieve and manage conversation sessions
Error Codes
Complete error reference
Rate Limits
Understand rate limiting
