Agents API
The Agents API allows external applications, scripts, and services to communicate with CompanyGPT agents programmatically. CompanyGPT is based on LibreChat and exposes two API-compatible interfaces.
Overview
Section titled “Overview”The Agents API provides two interfaces:
- OpenAI-compatible Chat Completions —
POST /api/agents/v1/chat/completions - Open Responses API —
POST /api/agents/v1/responses
Both interfaces are authenticated via API keys and support streaming responses, making it easy to integrate CompanyGPT agents into existing workflows that already use the OpenAI SDK or similar tooling.
Prerequisites
Section titled “Prerequisites”To use the Agents API, the following prerequisites must be met:
- API access must be enabled — An administrator must enable the
remoteAgentsconfiguration. - Generate an API key — Once access is enabled, you can create an API key in the CompanyGPT interface under Settings.
- Find your agent ID — Each agent has a unique ID (e.g.
agent_ulS_lcjGw...) that you use as themodelparameter.
Authentication
Section titled “Authentication”All requests to the Agents API must be authenticated with a Bearer token:
Authorization: Bearer sk-your-api-keyAPI keys are generated in the CompanyGPT interface and follow the format sk-....
Endpoints
Section titled “Endpoints”Chat Completions (OpenAI-compatible)
Section titled “Chat Completions (OpenAI-compatible)”POST /api/agents/v1/chat/completionsCompatible with the OpenAI Chat Completions format. The model parameter corresponds to the agent ID.
import { OpenAI } from "openai";
const client = new OpenAI({ baseURL: "https://<COMPANYGPT URL>/api/agents/v1", apiKey: "sk-your-api-key",});
const stream = await client.chat.completions.create({ model: "agent_ulS_lcjGw...", // Agent ID messages: [ { role: "user", content: "What can you help me with?", }, ], stream: true,});
let contentBuffer = "";const toolCalls = new Map();
for await (const event of stream) { const delta = event.choices?.[0]?.delta; if (!delta) continue;
// Stream text content if (delta.content) { contentBuffer += delta.content; process.stdout.write(delta.content); }
// Handle tool calls if (delta.tool_calls) { for (const toolCall of delta.tool_calls) { const toolId = toolCall.index || 0; if (!toolCalls.has(toolId)) { toolCalls.set(toolId, { id: toolCall.id, name: toolCall.function?.name || "", arguments: "", }); } if (toolCall.function?.arguments) { toolCalls.get(toolId).arguments += toolCall.function.arguments; } } }}
console.log(`\nDone. Tool calls: ${toolCalls.size}`);curl -X POST https://<COMPANYGPT URL>/api/agents/v1/chat/completions \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "agent_ulS_lcjGwTAG2Ly3zTcgz", "messages": [ {"role": "user", "content": "What can you help me with?"} ], "stream": true }'Open Responses API
Section titled “Open Responses API”POST /api/agents/v1/responsesThe Open Responses API follows the Open Responses standard — an open inference standard designed for agentic workflows with native support for tool use, structured outputs, and streaming. This is the primary interface going forward.
import { OpenAI } from "openai";
const client = new OpenAI({ baseURL: "https://<COMPANYGPT URL>/api/agents/v1", apiKey: "sk-your-api-key",});
const stream = await client.responses.create({ model: "agent_ulS_lcjGwTAG2Ly3zTcgz", // Agent ID input: [ { role: "user", content: "What can you help me with?", }, ], stream: true,});
for await (const event of stream) { console.log(event);}curl -X POST https://<COMPANYGPT URL>/api/agents/v1/responses \ -H "Authorization: Bearer sk-your-api-key" \ -H "Content-Type: application/json" \ -d '{ "model": "agent_ulS_lcjGwTAG2Ly3zTcgz", "input": "What can you help me with?" }'List Available Agents
Section titled “List Available Agents”GET /api/agents/v1/modelsReturns all agents accessible with your API key as a list of models.
import { OpenAI } from "openai";
const client = new OpenAI({ baseURL: "https://<COMPANYGPT URL>/api/agents/v1", apiKey: "sk-your-api-key",});
const models = await client.models.list();console.log(models);curl https://<COMPANYGPT URL>/api/agents/v1/models \ -H "Authorization: Bearer sk-your-api-key"Token Usage
Section titled “Token Usage”All Agents API requests are counted against the user’s token balance (when token spending is configured). Both input and output tokens are tracked, including cache tokens for providers that support them (OpenAI, Anthropic).
Related Documentation
Section titled “Related Documentation”- Agents — Creating and configuring agents in CompanyGPT
- MCP Servers — MCP server integrations