Skip to main content
POST
Creates a chat completion with an agent (Vercel AI SDK compatible)
⚠️ Using our API via a dedicated deployment? Just replace api.langdock.com with your deployment’s base URL: <deployment-url>/api/public
Creates a model response for a given agent ID, or pass in an Agent configuration that should be used for your request. This endpoint uses the Vercel AI SDK compatible message format for seamless integration with modern AI applications.
To share an agent with an API key, follow this guide
Vercel AI SDK Compatible: This endpoint uses the Vercel AI SDK’s UIMessage format, making it compatible with the useChat hook and other Vercel AI SDK features.
Using MCP: You can also access your agents via the Langdock MCP Server, which lets MCP-compatible AI clients call your agents directly.

Base URL

Request Parameters

Message Format (Vercel AI SDK UIMessage)

The Agents API uses the Vercel AI SDK’s UIMessage format for maximum compatibility with modern AI frameworks.

UIMessage Structure

Each message in the messages array should contain:

Message Part Types

User message parts (for sending): Agent message parts (returned in responses — include in conversation history when sending follow-up messages):

Example Messages

User Message with Text

User Message with Attachment

To attach files to a message, upload them via the Upload Attachment API and reference the returned UUIDs in the message’s metadata.attachments array. Do not use type: "file" parts for uploaded attachments — that format is reserved for inline file references (e.g., data URIs).

Agent Message with Tool Call

Agent Configuration

When creating a temporary agent using the agent parameter, you can specify:
  • name - Name of the agent (max 64 chars)
  • instructions - System instructions (max 16384 chars)
  • description - Optional description (max 256 chars)
  • temperature - Temperature between 0-1
  • model - Model ID to use (see Available Models for options)
  • capabilities - Enable features like web search, Create & work with files, image generation, canvas
  • knowledgeFolderIds - IDs of Knowledge bases to use
  • attachmentIds - Array of UUID strings identifying attachments to use
You can retrieve a list of available models using the Models API.
The inline agent configuration field names differ from the Create and Update Agent APIs. In particular, this endpoint uses instructions (plural) and temperature, while the CRUD endpoints use instruction (singular) and creativity. The completions endpoint also accepts a nested capabilities object, while the CRUD endpoints use flat boolean fields.
attachmentIds in the inline agent configuration is currently not functional — the agent will not be able to read the attached files. Instead, use metadata.attachments on individual messages to reference uploaded files per-message, or create a persistent agent with the attachments field via the Create Agent API.

Using Tools via API

When an agent has tools configured (called “Actions” in the Langdock UI), it will automatically use them to respond to API requests when appropriate. The connection must be set to “preselected connection” (shared with other users) for tool authentication to work.
Preselected connection setting in agent configuration
Tools with “Require human confirmation” enabled do not work via API—they require manual approval in the Langdock UI. To use a tool via API, disable this setting in the agent configuration.

Structured Output

You can specify a structured output format using the optional output parameter: The output parameter behavior depends on the specified type:
  • type: "object" with no schema: Forces the response to be a single JSON object (no specific structure)
  • type: "object" with schema: Forces the response to match the provided JSON Schema
  • type: "array" with schema: Forces the response to be an array of objects matching the provided schema
  • type: "enum": Forces the response to be one of the values specified in the enum array
You can use tools like easy-json-schema to generate JSON Schemas from example JSON objects.

Streaming Responses

When stream is set to true, the API returns a stream using the Vercel AI SDK streaming format, compatible with the useChat hook and other Vercel AI SDK features.
Non-streaming requests are terminated with an HTTP 524 error after 100 seconds. If your agent runs tools, generates long responses, or uses slower models, requests can exceed this limit. Set stream: true to keep the connection open and avoid timeouts.

Using with Vercel AI SDK useChat Hook

Manual Stream Handling

Obtaining Attachment IDs

To use attachments in your agent conversations, first upload the files using the Upload Attachment API. This returns an attachmentId (UUID) for each file. You can then use attachments in two ways:
  1. Per-message (recommended): Include the attachment UUIDs in the message’s metadata.attachments array. This lets you reference different files in different messages within the same conversation.
  2. Agent-level: Include the UUIDs in the attachments array when creating or updating a persistent agent. All messages sent to that agent will have access to these files.

Response Format

The API returns a JSON object containing a messages array with the agent’s response:

Standard Response

The response contains a messages array. Each message has:
  • id - Unique identifier for the message
  • role - Always "assistant" for completion responses
  • content - The agent’s text response as a plain string

Structured Output

When the request includes an output parameter, the response will automatically include an output field containing the formatted structured data. The type of this field depends on the requested output format:
  • If output.type was “object”: Returns a JSON object (with schema validation if schema was provided)
  • If output.type was “array”: Returns an array of objects matching the provided schema
  • If output.type was “enum”: Returns a string matching one of the provided enum values

Examples

Using an Existing Agent with Attachment

Using a Temporary Agent Configuration

Using Structured Output with Schema

Using with Next.js Server Actions

Rate Limits

The rate limit for the Agents Completions endpoint is 500 RPM (requests per minute) and 60,000 TPM (tokens per minute). Rate limits are defined at the workspace level - not at an API key level. Each model has its own rate limit. If you exceed your rate limit, you will receive a 429 Too Many Requests response. Please note that the rate limits are subject to change. Refer to this documentation for the most up-to-date information.

Error Handling

Common error status codes:
  • 400 - Invalid request parameters, malformed message format, agent not found, or agent not shared with API key
  • 401 - Invalid or missing API key
  • 429 - Rate limit exceeded
  • 500 - Server error
Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on API Key Best Practices.

Authorizations

Authorization
string
header
required

API key as Bearer token. Format "Bearer YOUR_API_KEY"

Body

application/json
agentId
string
required

ID of an existing agent to use

messages
object[]
required

Array of UIMessage objects (Vercel AI SDK format)

stream
boolean
default:false
output
object

Specification for structured output format. When type is object/array and no schema is provided, the response will be JSON but can have any structure. When the type is enum, you must provide an enum parameter with an array of strings as options.

imageResponseFormat
enum<string>

Response format for images generated by the agent. "url" returns a signed URL, "b64_json" returns base64-encoded image data.

Available options:
url,
b64_json

Response

Successful chat completion

UIMessage response (Vercel AI SDK format)

id
string
required
role
enum<string>
required
Available options:
assistant
parts
object[]
required
output
any

Structured output if requested