> ## Documentation Index
> Fetch the complete documentation index at: https://dialnexa.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Agent

> Create a new AI voice agent with a custom voice, LLM, prompt, and telephony settings.

<Warning>
  **Legacy endpoint - deprecated.** Unversioned endpoints are scheduled for removal on **July 31, 2026**. Use the [`/v1` version](/docs/api-reference/v1/agents/create) for new integrations. This endpoint remains available for existing integrations until then.
</Warning>

Agents are the core building block in DialNexa. Each agent defines how an AI-powered call should sound and behave, including what it says, how it responds, and what it can do.

## When to use this

Use this endpoint to programmatically create agents as part of your onboarding flow, template system, or multi-tenant setup. For example, if each of your customers needs their own agent pre-configured with their business details, this lets you spin them up automatically.

## Key fields

* **`pipeline_type`:** Use `Cascaded` for the standard STT, LLM, and TTS pipeline. Use `Speech_To_Speech` for realtime speech models such as GPT realtime.
* **`prompts.prompt_text`:** The system prompt that shapes the agent's personality, instructions, and scope. Write it clearly; the LLM follows this closely.
* **`voice`:** Pass a voice `id` from [List Voices](/docs/api-reference/v1/voices/list), or configure it inline.
* **`speech.transcriber_id`:** Selects the primary STT provider for cascaded agents. Speech to Speech agents do not use a separate transcriber.
* **`speech.fallback_stt_enabled`:** Enables a backup STT provider for cascaded agents. When enabled, also send `speech.stt_fallback_transcriber_id`.
* **`speech.audio_cache_enabled`:** Caches repeated TTS phrases for lower latency on cascaded agents. Speech to Speech agents do not use TTS audio cache.
* **`telephony.call_limits`:** Set how long a call can run, how long to wait before ending on silence, and how long to ring before giving up.
* **`functions`:** Tools the agent can invoke mid-call, such as calendar booking, CRM lookups, or custom webhooks.
* **`analysis.postcall_analysis`:** Fields to extract from the transcript after each call (e.g., CSAT score, intent, outcome).
* **`metadata` via dynamic variables:** You can reference `{{variable_name}}` in your prompt; values are injected at call time from the call's `metadata` object.

## Pipeline Types

| Pipeline type      | Use it when                                                    | Notes                                                                                                                          |
| ------------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `Cascaded`         | You want separate transcriber, LLM, and voice controls.        | This is the default for single prompt agents and supports fallback STT, voice model pricing, and Audio Cache.                  |
| `Speech_To_Speech` | You want a realtime speech model to listen and speak directly. | The model selector is limited to speech-to-speech models, and voice model, transcriber, and Audio Cache controls are not used. |


## OpenAPI

````yaml POST /agents2
openapi: 3.0.0
info:
  title: DialNexa API
  description: >-
    Public REST API for the DialNexa voice AI platform. Versioned endpoints are
    under /v1; unversioned endpoints are legacy and deprecated.
  version: 1.0.0
servers:
  - url: https://api.dialnexa.com
    description: DialNexa production API
security:
  - bearer: []
tags:
  - name: API Keys
  - name: Agent Functions
  - name: Agents V1
  - name: Agents2
  - name: Batch Calls
  - name: Batch Calls V1
  - name: Call Logs
  - name: Calls
  - name: Calls V1
  - name: Campaign Leads
  - name: Campaigns
  - name: External Webhooks
  - name: Knowledge Base
  - name: Knowledge Base V1
  - name: LLMs
  - name: LLMs V1
  - name: Languages
  - name: Languages V1
  - name: Organization Phone Numbers
  - name: Organization Phone Numbers V1
  - name: Phone Number Pricing
  - name: Phone Number Pricing V1
  - name: Transcribers
  - name: Transcribers V1
  - name: User Webhooks
  - name: User Webhooks V1
  - name: V1
  - name: Voices
  - name: Voices V1
  - name: Webcall
  - name: Workflow Leads
  - name: Workflow Leads V1
  - name: Workflows
  - name: Workflows V1
paths:
  /agents2:
    post:
      tags:
        - Agents2
      summary: Create a new agent (structured response)
      description: >-
        **Legacy endpoint - deprecated, scheduled for removal on July 31,
        2026.** Use the `/v1` version for new integrations. 
      operationId: Agents2Controller_create
      parameters:
        - name: x-organization-id
          in: header
          description: RSA encrypted organization ID (base64 format)
          required: true
          schema:
            type: string
            example: BASE64_ENCRYPTED_ORG_ID_HERE
      requestBody:
        required: true
        description: >-
          Grouped request body. Fallback LLM: set
          llm.fallback.fallback_llm_enabled and llm.fallback.llm_fallback_model
          (or fall_back_llm_id). PCA: set analysis.postcall_analysis with
          field_name, field_type, field_description, and optional
          additional_fields.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAgents2BodyDto'
      responses:
        '201':
          description: >-
            Agent created; current_version includes llm.fallback and flat
            fallback fields
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Agents2VersionResponseDto'
      deprecated: true
components:
  schemas:
    CreateAgents2BodyDto:
      type: object
      properties:
        title:
          type: string
          example: Customer Support Agent
        llm:
          $ref: '#/components/schemas/Agents2LlmDto'
        fallback_llm_enabled:
          type: boolean
          description: >-
            Enable fallback LLM (flat alias; prefer
            llm.fallback.fallback_llm_enabled)
          example: false
        llm_fallback_model:
          type: string
          description: Fallback LLM id (flat alias; prefer llm.fallback.llm_fallback_model)
          example: abc123xyz789ab
          nullable: true
        llm_fallback_delay_ms:
          type: number
          description: >-
            Fallback delay ms (flat alias; prefer
            llm.fallback.llm_fallback_delay_ms)
          example: 500
          nullable: true
        analysis:
          description: Post-call analysis (PCA) fields for the agent version
          allOf:
            - $ref: '#/components/schemas/Agents2AnalysisDto'
    Agents2VersionResponseDto:
      type: object
      properties:
        number:
          type: number
          example: 0
        is_published:
          type: boolean
          example: false
        llm:
          $ref: '#/components/schemas/Agents2LlmDto'
        fallback_llm_enabled:
          type: boolean
          example: false
        llm_fallback_model:
          type: string
          example: llm_abc123xyz789ab
          nullable: true
        fall_back_llm_id:
          type: string
          example: llm_abc123xyz789ab
          nullable: true
        llm_fallback_delay_ms:
          type: number
          example: 500
          nullable: true
        transcriber_id:
          type: string
          example: tr0deepnova3xx
          nullable: true
        analysis:
          $ref: '#/components/schemas/Agents2AnalysisDto'
      required:
        - number
        - is_published
    Agents2LlmDto:
      type: object
      properties:
        id:
          type: string
          description: Primary LLM id (llms.id)
          example: llm_xxxxx
        settings:
          $ref: '#/components/schemas/Agents2LlmSettingsDto'
        fallback:
          $ref: '#/components/schemas/Agents2LlmFallbackDto'
    Agents2AnalysisDto:
      type: object
      properties:
        postcall_analysis:
          description: Post-call analysis fields to create on the agent version
          example:
            - field_name: customer_satisfaction
              field_type: NUMBER
              field_description: Customer satisfaction rating
          type: array
          items:
            $ref: '#/components/schemas/Agents2PostCallAnalysisItemDto'
    Agents2LlmSettingsDto:
      type: object
      properties:
        temperature:
          type: number
          description: LLM temperature (0.0 to 2.0)
          example: 0.1
        structured_output:
          type: boolean
          description: Enable structured JSON output
          example: true
    Agents2LlmFallbackDto:
      type: object
      properties:
        fallback_llm_enabled:
          type: boolean
          description: Enable fallback LLM for this agent version
          example: false
        llm_fallback_model:
          type: string
          description: ID (llms.id) of the LLM to use as fallback
          example: abc123xyz789ab
          nullable: true
        fall_back_llm_id:
          type: string
          description: Alias for llm_fallback_model (llms.id); llm_ prefix is stripped
          example: llm_abc123xyz789ab
          nullable: true
        llm_fallback_delay_ms:
          type: number
          description: Milliseconds to wait before triggering the fallback LLM
          example: 500
          nullable: true
    Agents2PostCallAnalysisItemDto:
      type: object
      properties:
        field_name:
          type: string
          example: customer_satisfaction
          description: Name of the PCA field
        field_description:
          type: string
          example: Customer satisfaction rating from 1 to 5
          description: Description of the PCA field
        field_type:
          type: string
          example: NUMBER
          description: Type of the PCA field
          enum:
            - TEXT
            - SELECTOR
            - BOOLEAN
            - NUMBER
        additional_fields:
          example:
            - positive
            - neutral
            - negative
          description: Selector choices (required for SELECTOR type)
          type: array
          items:
            type: string
      required:
        - field_name
        - field_type
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http

````