Skip to content
ajan.io

Docs menu

On this page

Agent Create API

Create a new agent programmatically

Creates a new agent in your workspace programmatically. The created agent can be used via the chat completions endpoint or accessed through the ajan UI.

Before You Start

  • API key scope: Requires an API key with the Agent API scope. Created agents are automatically shared with the API key for use in chat completions.
  • Legacy Assistants API: This is the new Agents API with native Vercel AI SDK compatibility. If you're using the legacy Assistants API, see the migration guide.

Base URL

https://api.ajan.io/agent/v1/create

Parameters

ParameterTypeRequiredDescription
namestringYesName of the agent (1-80 characters)
descriptionstringNoDescription of what the agent does (max 800 chars)
emojistringNoEmoji icon for the agent (max 16 chars, e.g., "πŸ€–")
instructionstringNoSystem prompt/instructions for the agent (max 50000 chars)
inputTypestringNoInput type: "PROMPT", "STRUCTURED", "INTEGRATION", "SCHEDULED", or "WEBHOOK" (default: "PROMPT")
modelstringNoModel identifier to use (deployment name from the Models API). Uses workspace default if not provided
creativitynumberNoTemperature between 0-1 (default: 0.3)
conversationStartersstring\[]NoArray of suggested prompts to help users get started (max 20, each 1-255 chars)
actionsarrayNoArray of action objects for custom integrations
inputFieldsarrayNoArray of form field definitions (for STRUCTURED input type)
attachmentsstring\[]NoArray of up to 50 attachment UUIDs to include with the agent
knowledgeFolderIdsstring\[]NoArray of Folder UUIDs to include with the agent
webSearchbooleanNoEnable web search capability (default: false)
imageGenerationbooleanNoEnable image generation capability (default: false)
dataAnalystbooleanNoAccepted for compatibility. See warning below
extendedThinkingbooleanNoEnable extended thinking mode (default: false)

Actions Configuration

Each action in the actions array should contain:

  • actionId (required) - UUID of the action from an enabled integration
  • requiresConfirmation (optional) - Whether to require user confirmation before executing (default: true)

Input Fields Configuration

When using inputType: "STRUCTURED", you can define form fields in the inputFields array:

FieldTypeRequiredDescription
slugstringYesUnique identifier for the field
typestringYesField type (see supported types below)
labelstringYesDisplay label for the field
descriptionstringNoHelp text for the field
requiredbooleanNoWhether the field is required (default: false)
ordernumberYesDisplay order (0-indexed)
optionsstring\[]NoOptions for SELECT and MULTI\_SELECT type fields
fileTypesstringNoAllowed file types for FILE type fields (nullable)
emailDomainstringNoAllowed email domain for EMAIL type fields

Supported Field Types:

  • TEXT - Single line text input
  • MULTI_LINE_TEXT - Multi-line text area
  • NUMBER - Numeric input
  • CHECKBOX - Boolean checkbox
  • FILE - File upload
  • SELECT - Dropdown selection
  • MULTI_SELECT - Multi-select
  • DATE - Date picker
  • EMAIL - Email address

Obtaining Attachment IDs

To include attachments with your agent, first upload files using the Upload Attachment API. This will return attachment UUIDs that you can include in the attachments array.

Examples

Creating a Basic Agent

javascript
const axios = require("axios");

async function createBasicAgent() {
  const response = await axios.post(
    "https://api.ajan.io/agent/v1/create",
    {
      name: "Document Analyzer",
      description: "Analyzes and summarizes documents",
      emoji: "πŸ“„",
      instruction: "You are a helpful agent that analyzes documents and provides clear summaries of key information.",
      creativity: 0.5,
      conversationStarters: [
        "Summarize this document",
        "What are the key points?",
        "Extract action items"
      ],
      webSearch: false
    },
    {
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
      }
    }
  );

  console.log("Agent created:", response.data.agent.id);
}

Validation Rules

The API enforces several validation rules:

  • Model - Must be in your workspace's active models list
  • Actions - Must belong to integrations enabled in your workspace
  • Attachments - Must exist in your workspace and not be deleted
  • Folders - Must exist in your workspace and not be deleted
  • Permissions - Your API key must have the createAgents permission
  • Name - Must be between 1-80 characters
  • Description - Maximum 800 characters
  • Instruction - Maximum 50000 characters
  • Creativity - Must be between 0 and 1

Important Notes

  • Created agents are automatically shared with your API key for use in chat completions
  • The API key creator becomes the owner and can manage the agent in the UI
  • Attachments are bidirectionally linked to the agent
  • createdBy and workspaceId are automatically set from your API key

Response Format

Success Response (201 Created)

typescript
{
  status: "success";
  message: "Agent created successfully";
  agent: {
    id: string;
    name: string;
    description: string | null;
    instruction: string | null;
    emojiIcon: string | null;
    model: string | null;
    temperature: number;
    conversationStarters: string[];
    inputType: "PROMPT" | "STRUCTURED" | "INTEGRATION" | "SCHEDULED" | "WEBHOOK";
    webSearchEnabled: boolean;
    imageGenerationEnabled: boolean;
    canvasEnabled: boolean;
    extendedThinking: boolean;
    actions: Array<{
      actionId: string;
      requiresConfirmation: boolean;
    }>;
    inputFields: Array<{
      type: "TEXT" | "MULTI_LINE_TEXT" | "NUMBER" | "CHECKBOX" | "FILE" | "SELECT" | "MULTI_SELECT" | "DATE" | "EMAIL";
      label: string;
      description: string | null;
      required: boolean;
      order: number;
    }>;
    attachments: string[];
    knowledgeFolderIds: string[];
    owner: {
      id: string;
      name: string | null;
      email: string;
    } | null;
    createdAt: string;
    updatedAt: string;
  };
}

Error Handling

typescript
try {
  const response = await axios.post('https://api.ajan.io/agent/v1/create', ...);
} catch (error) {
  if (error.response) {
    switch (error.response.status) {
      case 400:
        console.error('Invalid parameters or resource not found:', error.response.data.message);
        break;
      case 401:
        console.error('Invalid or missing API key');
        break;
      case 403:
        console.error('Insufficient permissions - requires Agent API scope');
        break;
      case 429:
        console.error('Rate limit exceeded');
        break;
      case 500:
        console.error('Server error');
        break;
    }
  }
}

OpenAPI

openapi: 3.0.0
info:
  title: ajan API
  version: 3.0.0
servers:
  - url: https://api.ajan.io
    description: Production
security:
  - bearerAuth: []
paths:
  /agent/v1/create:
    post:
      tags:
        - Agent Build
      summary: Creates a new agent
      description: Creates a new agent in your workspace programmatically.
      operationId: createAgentV2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssistantCreateRequest'
      responses:
        '201':
          description: Agent created successfully
          content:
            application/json:
              schema:
                type: object
                required:
                  - status
                  - message
                  - agent
                properties:
                  status:
                    type: string
                    enum:
                      - success
                  message:
                    type: string
                  agent:
                    $ref: '#/components/schemas/AssistantDetails'
components:
  schemas:
    AssistantCreateRequest:
      allOf:
        - $ref: '#/components/schemas/AssistantWriteRequest'
        - type: object
          required:
            - name
          properties:
            inputType:
              default: PROMPT
            creativity:
              default: 0.3
            conversationStarters:
              default: []
            actions:
              default: []
            inputFields:
              default: []
            webSearch:
              default: false
            imageGeneration:
              default: false
            dataAnalyst:
              default: false
            extendedThinking:
              default: false
            attachments:
              default: []
            knowledgeFolderIds:
              default: []
    AssistantDetails:
      type: object
      required:
        - id
        - name
        - description
        - instruction
        - emojiIcon
        - model
        - temperature
        - conversationStarters
        - inputType
        - webSearchEnabled
        - imageGenerationEnabled
        - canvasEnabled
        - extendedThinking
        - actions
        - inputFields
        - attachments
        - knowledgeFolderIds
        - createdAt
        - updatedAt
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier for the agent
        name:
          type: string
          description: Name of the agent
        description:
          type: string
          nullable: true
          description: Description of what the agent does
        instruction:
          type: string
          nullable: true
          description: System prompt/instructions for the agent
        emojiIcon:
          type: string
          nullable: true
          description: Emoji icon for the agent
        model:
          type: string
          nullable: true
          description: Model ID to use (see Models for Agent API)
        temperature:
          type: number
          minimum: 0
          maximum: 1
          description: Temperature/creativity setting for response generation
        conversationStarters:
          type: array
          items:
            type: string
          description: Array of suggested prompts to help users get started
        inputType:
          type: string
          enum:
            - PROMPT
            - STRUCTURED
            - INTEGRATION
            - SCHEDULED
            - WEBHOOK
          description: Input type for the agent
        webSearchEnabled:
          type: boolean
          description: Whether web search capability is enabled
        imageGenerationEnabled:
          type: boolean
          description: Whether image generation capability is enabled
        canvasEnabled:
          type: boolean
          description: Whether canvas capability is enabled
        extendedThinking:
          type: boolean
          description: >-
            Whether extended thinking is enabled. Only supported on models that
            expose this capability; enabling it on an unsupported model returns
            a 400 error.
        actions:
          type: array
          items:
            type: object
            required:
              - actionId
              - requiresConfirmation
            properties:
              actionId:
                type: string
                format: uuid
                description: UUID of the action from an enabled integration
              requiresConfirmation:
                type: boolean
                description: Whether user confirmation is required before executing
          description: Array of action objects for custom integrations
        inputFields:
          type: array
          items:
            type: object
            required:
              - type
              - label
              - description
              - required
              - order
            properties:
              type:
                type: string
                enum:
                  - TEXT
                  - MULTI_LINE_TEXT
                  - NUMBER
                  - CHECKBOX
                  - FILE
                  - SELECT
                  - MULTI_SELECT
                  - DATE
                  - EMAIL
                description: Field type
              label:
                type: string
                description: Display label for the field
              description:
                type: string
                nullable: true
                description: Help text for the field
              required:
                type: boolean
                description: Whether the field is required
              order:
                type: integer
                minimum: 0
                description: Display order (0-indexed)
          description: Array of form field definitions (for STRUCTURED input type)
        attachments:
          type: array
          items:
            type: string
            format: uuid
          description: Array of attachment UUIDs associated with the agent
        knowledgeFolderIds:
          type: array
          items:
            type: string
            format: uuid
          description: Array of Folder UUIDs associated with the agent
        createdAt:
          type: string
          format: date-time
          description: Timestamp when the agent was created
        updatedAt:
          type: string
          format: date-time
          description: Timestamp when the agent was last updated
    AssistantWriteRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 80
          description: Name of the agent or assistant
        description:
          type: string
          maxLength: 800
          description: >-
            Description of what the agent or assistant does. Send an empty
            string to clear it during an update.
        instruction:
          type: string
          maxLength: 50000
          description: >-
            System prompt or instructions. Send an empty string to clear it
            during an update.
        inputType:
          type: string
          enum:
            - PROMPT
            - STRUCTURED
            - INTEGRATION
            - SCHEDULED
            - WEBHOOK
          description: Input type
        emoji:
          type: string
          nullable: true
          maxLength: 16
          description: Emoji icon
        model:
          type: string
          description: Model deployment name
        creativity:
          type: number
          minimum: 0
          maximum: 1
          description: Temperature for response generation
        conversationStarters:
          type: array
          maxItems: 20
          items:
            type: string
            minLength: 1
            maxLength: 255
          description: Suggested prompts
        actions:
          type: array
          items:
            $ref: '#/components/schemas/AssistantActionRequest'
          description: Actions that the agent or assistant can use
        inputFields:
          type: array
          items:
            $ref: '#/components/schemas/AssistantInputFieldRequest'
          description: Form fields for STRUCTURED input
        webSearch:
          type: boolean
          description: Enable web search
        imageGeneration:
          type: boolean
          description: Enable image generation
        dataAnalyst:
          type: boolean
          deprecated: true
          description: Deprecated. Accepted for compatibility and ignored.
        extendedThinking:
          type: boolean
          description: Enable extended thinking
        attachments:
          type: array
          maxItems: 50
          items:
            type: string
            format: uuid
          description: Attachment UUIDs
        knowledgeFolderIds:
          type: array
          items:
            type: string
            format: uuid
          description: Folder UUIDs
    AssistantActionRequest:
      type: object
      required:
        - actionId
      properties:
        actionId:
          type: string
          format: uuid
          description: UUID of the action from an enabled integration
        requiresConfirmation:
          type: boolean
          default: true
          description: Whether to require user confirmation before executing
    AssistantInputFieldRequest:
      type: object
      required:
        - slug
        - type
        - label
        - order
      properties:
        slug:
          type: string
          minLength: 1
          maxLength: 64
          description: Unique identifier for the field
        type:
          type: string
          enum:
            - TEXT
            - MULTI_LINE_TEXT
            - NUMBER
            - CHECKBOX
            - FILE
            - SELECT
            - MULTI_SELECT
            - DATE
            - EMAIL
          description: Field type
        label:
          type: string
          minLength: 1
          maxLength: 255
          description: Display label for the field
        description:
          type: string
          maxLength: 512
          description: Help text for the field
        required:
          type: boolean
          default: false
          description: Whether the field is required
        order:
          type: integer
          minimum: 0
          description: Display order
        options:
          type: array
          default: []
          items:
            type: string
            minLength: 1
            maxLength: 255
          description: Options for SELECT and MULTI_SELECT fields
        fileTypes:
          type: string
          nullable: true
          maxLength: 255
          description: Allowed file types for FILE fields
        emailDomain:
          type: string
          nullable: true
          description: Allowed email domain for EMAIL fields
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"