OpenAI-compatible API
Use Pegasus bots from OpenAI-compatible SDKs and tools.
Pro and Ultra workspaces can chat with Pegasus bots from any tool that already supports OpenAI chat completions.
Use the base URL https://<your-pegasus-host>/api/v1, and use a Personal Access Token as the OpenAI api_key. The HTTP header is Authorization: Bearer pat_....
Before you start:
- Create a PAT in API tokens & scopes.
- Store the PAT safely. See Secure your token.
- Give the token
messages:sendfor chat completions andmodels:readto list models. - Use a workspace with API access. Free workspaces cannot use this API.
Responses and errors are plain OpenAI-style JSON. They are not wrapped in the standard Pegasus success or error envelope.
Quickstart
Set PEGASUS_API_KEY to a PAT such as pat_..., then point the official SDK or curl at your Pegasus host.
curl https://<your-pegasus-host>/api/v1/chat/completions \
-H "Authorization: Bearer $PEGASUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "<your-bot-id>",
"messages": [
{ "role": "user", "content": "Summarize our refund policy." }
]
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://<your-pegasus-host>/api/v1",
api_key=os.environ["PEGASUS_API_KEY"],
)
completion = client.chat.completions.create(
model="<your-bot-id>",
messages=[{"role": "user", "content": "Summarize our refund policy."}],
)
print(completion.choices[0].message.content)import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://<your-pegasus-host>/api/v1',
apiKey: process.env.PEGASUS_API_KEY,
})
const completion = await client.chat.completions.create({
model: '<your-bot-id>',
messages: [{ role: 'user', content: 'Summarize our refund policy.' }],
})
console.log(completion.choices[0].message.content)Model strings and the model list
The model value selects the bot and, optionally, the LLM alias.
| Form | Meaning |
|---|---|
<bot_id> | Use the bot with the plan's default LLM route. |
<bot_id>:<llm_alias> | Use the bot with a selectable alias from the LLM routing catalog. |
The easiest way to get this value is from the bot's API tab: under Choose the model, pick Plan default or a specific AI model, then click Copy model. If the bot is not Ready, the API tab shows "Train the bot to use the API" with Go to training sources instead, because the API answers only after the bot is trained.
Call GET /api/v1/models with the models:read scope to see what the token can use. The response is an OpenAI list object containing model ids such as <bot_id> and <bot_id>:<llm_alias>.
GET /api/v1/models/{id} returns one OpenAI model object for an id that appears in the list. An id that does not exist, that you cannot access, whose bot is not ready, that is malformed, or that is above your plan returns 404 with error.code set to UNKNOWN_MODEL.
Only bots with the Ready status are listed. Aliases are filtered by the caller's plan: a Free workspace cannot use the API, and a lower plan does not see aliases it cannot select.
Streaming
Set stream: true to receive OpenAI chat.completion.chunk frames. With the official JavaScript SDK, loop over the stream:
const stream = await client.chat.completions.create({
model: '<your-bot-id>:<llm_alias>',
messages: [{ role: 'user', content: 'Draft a short welcome message.' }],
stream: true,
stream_options: { include_usage: true },
})
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content
if (text) {
process.stdout.write(text)
}
if (chunk.usage) {
console.log('\nusage', chunk.usage)
}
}The stream uses Server-Sent Events and normally ends with data: [DONE]. When stream_options.include_usage is true, Pegasus sends one final usage chunk before [DONE]; that chunk has choices: [] and a usage object.
If an error happens before any output, Pegasus returns a normal HTTP error response in the OpenAI error format. If an upstream error happens after output has started, Pegasus sends one SSE frame shaped as data: {"error":...} and closes the stream without data: [DONE].
Errors
Errors use the plain OpenAI format:
{
"error": {
"message": "Daily credit limit reached. Resets at midnight UTC.",
"type": "insufficient_quota",
"param": null,
"code": "DAILY_LIMIT_REACHED"
}
}error.code is the stable Pegasus error code. error.message is human-readable and can change.
| HTTP | OpenAI error.type | Common Pegasus error.code values |
|---|---|---|
| 400 | invalid_request_error | VALIDATION_ERROR |
| 401 | authentication_error | PAT_INVALID, PAT_INVALID_OR_EXPIRED |
| 403 | permission_error | PAT_SCOPE_INSUFFICIENT, PLAN_LIMIT_EXCEEDED, PAT_NOT_ALLOWED, BOT_NOT_READY, TEAM_QUOTA_DISABLED, TEAM_SEAT_FEATURE_UNAVAILABLE |
| 404 | not_found_error | UNKNOWN_MODEL |
| 429 | rate_limit_error | RATE_LIMITED |
| 429 | insufficient_quota | DAILY_LIMIT_REACHED |
| 5xx | server_error | AI_SERVICE_UNAVAILABLE, INTERNAL_ERROR |
Limits, quota, and usage
- Chat uses
POST /api/v1/chat/completionsand themessages:sendscope. - Listing models uses
GET /api/v1/modelsandGET /api/v1/models/{id}with themodels:readscope. - A request can include 1 to 50 messages.
- Total message content can be at most 100,000 characters.
- Each message
contentmust be a string. Multimodal content-part arrays are not supported. - The last message must have role
user. - Chat without streaming is limited to 20 requests per 60 seconds.
- Chat with streaming is limited to 10 requests per 60 seconds.
- Model endpoints use the default (light) API rate limits.
- Chat uses the same daily credits as chat in the Dashboard. Usage is recorded with
source=API. - The API is stateless. Pegasus does not create conversations or messages; send the full history in each request.
Not supported in v1
The v1 OpenAI-compatible API supports only chat completions and the model list.
These are not supported:
- Embeddings.
- Responses API.
- Tool or function calling.
- Vision or other multimodal input.
- New
sk-...API keys. Usepat_...Personal Access Tokens. - A bare
/v1base path. Use/api/v1.