Skip to main content

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

Subscription Required: This API is only available for Basic or Pro subscribers.If you don’t have an active subscription, you’ll receive a 403 Forbidden error. Visit junis.ai/subscription to start a plan.

Endpoint

Authentication

Include your API key in the X-API-Key header:
Required Scope: 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:
Role Types:
  • system: System instructions (optional, rarely needed with Junis)
  • user: User messages
  • assistant: 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 with stream: true.

Streaming Request

cURL

Streaming Response Format

Server-Sent Events (SSE) format:
Key Points:
  • Each line starts with data:
  • First chunk contains role
  • Subsequent chunks contain content deltas
  • Final chunk has finish_reason
  • Every chunk includes session_id for 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), use token_agent events to correctly attribute tokens:
When to use agent events:
  • Build agent pipeline visualizations
  • Track per-agent performance metrics
  • Handle Parallel Agent outputs separately
  • Debug multi-agent workflows

Session Management

Junis supports explicit session management via session_id parameter, allowing you to control conversation context precisely.

How Sessions Work

Session ID Usage

Recommended: Always capture the session_id from the first response and include it in subsequent requests to maintain conversation context.
Behavior:

Example: Continuing a Conversation

Viewing Sessions

Retrieve your sessions via the Sessions API:
See Sessions API for details.

Function Calling (Tool Use)

Current Implementation: Tool calling uses keyword pattern matching, not LLM-native function calling.Supported tools:
  • end_call: Detects phrases like “안녕히”, “감사합니다”, “goodbye”
  • transfer_call: Detects phrases like “상담원 연결”, “전화 연결”, “connect agent”
Full LLM-native function calling support is in development.
When a supported keyword is detected in the assistant’s response, the API returns a tool_calls object with finish_reason: "tool_calls".

Error Handling

Common Errors

Error Types


Best Practices

  • Use Streaming: Enable stream: true for 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