Creates a chat completion with an agent (Vercel AI SDK compatible)
Agents API
Agents Completions API
Creates a model response for a given Agent using Vercel AI SDK compatible format.
POST
Creates a chat completion with an agent (Vercel AI SDK compatible)
Documentation Index
Fetch the complete documentation index at: https://docs.langdock.com/llms.txt
Use this file to discover all available pages before exploring further.
⚠️ Using our API via a dedicated deployment? Just replace
api.langdock.com with your deployment’s base URL: <deployment-url>/api/publicTo 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.Base URL
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
agentId | string | One of agentId/agent required | ID of an existing agent to use |
agent | object | One of agentId/agent required | Configuration for a temporary agent |
messages | array | Yes | Array of UIMessage objects (Vercel AI SDK format) |
stream | boolean | No | Enable streaming responses (default: false) |
output | object | No | Structured output format specification |
maxSteps | integer | No | Maximum number of tool steps (1-20) |
imageResponseFormat | string | No | Response format for agent-generated images. "url" returns a signed URL, "b64_json" returns base64-encoded image data. |
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 themessages array should contain:
Message Part Types
User message parts (for sending):| Type | Fields | Description |
|---|---|---|
text | type: "text", text: string | Plain text content |
file | type: "file", mediaType: string, url: string, filename?: string | Inline file reference |
| Type | Key Fields | Description |
|---|---|---|
text | type: "text", text: string | Text response |
reasoning | type: "reasoning", text: string | Model reasoning / chain-of-thought |
tool-{name} | type: "tool-{name}", toolCallId: string, state: "input-streaming" | "input-available" | "output-available" | "output-error", input?: any, output?: any, errorText?: string | Tool call and result |
source-url | type: "source-url", sourceId: string, url: string, title?: string | Web source reference |
source-document | type: "source-document", sourceId: string, mediaType: string, title: string, filename?: string | Document source reference |
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 theagent 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-1model- Model ID to use (see Available Models for options)capabilities- Enable features like web search, data analysis, image generation, canvasknowledgeFolderIds- IDs of knowledge folders to useattachmentIds- Array of UUID strings identifying attachments to use
You can retrieve a list of available models using the Models 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.
Structured Output
You can specify a structured output format using the optionaloutput parameter:
| Field | Type | Description |
|---|---|---|
type | ”object” | “array” | “enum” | The type of structured output |
schema | object | JSON Schema definition for the output (for object/array types) |
enum | string[] | Array of allowed values (for enum type) |
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 Schematype: "array"with schema: Forces the response to be an array of objects matching the provided schematype: "enum": Forces the response to be one of the values specified in theenumarray
You can use tools like easy-json-schema to generate JSON Schemas from example JSON objects.
Streaming Responses
Whenstream 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.
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 anattachmentId (UUID) for each file. You can then use attachments in two ways:
- Per-message (recommended): Include the attachment UUIDs in the message’s
metadata.attachmentsarray. This lets you reference different files in different messages within the same conversation. - Agent-level: Include the UUIDs in the
attachmentsarray 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 amessages array with the agent’s response:
Standard Response
The response contains amessages array. Each message has:
id- Unique identifier for the messagerole- Always"assistant"for completion responsescontent- The agent’s text response as a plain string
Structured Output
When the request includes anoutput 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.typewas “object”: Returns a JSON object (with schema validation if schema was provided) - If
output.typewas “array”: Returns an array of objects matching the provided schema - If
output.typewas “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 a429 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
400- Invalid request parameters, malformed message format, agent not found, or agent not shared with API key401- Invalid or missing API key429- Rate limit exceeded500- 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
API key as Bearer token. Format "Bearer YOUR_API_KEY"
Body
application/json
ID of an existing agent to use
Array of UIMessage objects (Vercel AI SDK format)
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.
- Option 1
- Option 2
- Option 3
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