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

# Create Message

> Add a new message to the conversation. Used to insert a new messages to a conversation manually ( without using chat endpoint )



## OpenAPI

````yaml /openapi/source/external/inference/inference-embedding.json post /ai/conversations/{conversation_id}/message
openapi: 3.1.0
info:
  version: 2.0.0
  title: Telnyx API
  x-latency-category: responsive
  x-endpoint-cost: light
  description: SIP trunking, SMS, MMS, Call Control and Telephony Data Services.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
    description: Version 2.0.0 of the Telnyx API
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: Generate text with LLMs
  - name: Assistants
    description: Configure AI assistant specifications
  - name: Conversations
    description: Manage historical AI assistant conversations
  - name: File-based Text-to-Speech
    description: Turn audio into text or text into audio.
  - name: Embeddings
    description: Embed documents and perform text searches
  - name: Clusters
    description: Identify common themes and patterns in your embedded documents
  - name: Fine Tuning
    description: Customize LLMs for your unique needs
  - name: OpenAI Embeddings
    description: >-
      OpenAI-compatible embeddings endpoints for generating vector
      representations of text
paths:
  /ai/conversations/{conversation_id}/message:
    post:
      tags:
        - Conversations
      summary: Create Message
      description: >-
        Add a new message to the conversation. Used to insert a new messages to
        a conversation manually ( without using chat endpoint )
      operationId: add_new_message
      parameters:
        - name: conversation_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            description: The ID of the conversation
            title: Conversation Id
          description: The ID of the conversation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMsgReq'
            example:
              role: Role
              content: ''
              name: Name
              tool_choice: string
              tool_calls: []
              tool_call_id: Tool Call Id
              sent_at: '2024-01-23T18:10:02.574Z'
      responses:
        '200':
          description: Successful Response
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
              example:
                detail:
                  - loc:
                      - string
                    msg: Message
                    type: Error Type
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Telnyx from 'telnyx';


            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });


            await
            client.ai.conversations.addMessage('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
            { role: 'role' });
        - lang: Python
          source: |
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            client.ai.conversations.add_message(
                conversation_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                role="role",
            )
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\terr := client.AI.Conversations.AddMessage(\n\t\tcontext.TODO(),\n\t\t\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\",\n\t\ttelnyx.AIConversationAddMessageParams{\n\t\t\tRole: \"role\",\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.ai.conversations.ConversationAddMessageParams;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    ConversationAddMessageParams params = ConversationAddMessageParams.builder()
                        .conversationId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
                        .role("role")
                        .build();
                    client.ai().conversations().addMessage(params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            result =
            telnyx.ai.conversations.add_message("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
            role: "role")


            puts(result)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $result = $client->ai->conversations->addMessage(
                '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
                role: 'role',
                content: 'content',
                metadata: ['foo' => 'string'],
                name: 'name',
                sentAt: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                toolCallID: 'tool_call_id',
                toolCalls: [['foo' => 'bar']],
                toolChoice: 'string',
              );

              var_dump($result);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx ai:conversations add-message \
              --api-key 'My API Key' \
              --conversation-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e \
              --role role
components:
  schemas:
    CreateMsgReq:
      properties:
        role:
          type: string
          title: Role
        content:
          type: string
          title: Content
          default: ''
        name:
          type: string
          title: Name
        tool_choice:
          anyOf:
            - type: string
            - type: object
              title: ToolChoiceObject
          title: Tool Choice
        tool_calls:
          items:
            type: object
            additionalProperties: true
          type: array
          title: Tool Calls
        tool_call_id:
          type: string
          title: Tool Call Id
        sent_at:
          type: string
          format: date-time
          title: Sent At
        metadata:
          type: object
          additionalProperties:
            anyOf:
              - type: string
              - type: integer
              - type: boolean
              - items:
                  anyOf:
                    - type: string
                    - type: integer
                    - type: boolean
                type: array
          title: Metadata
      type: object
      required:
        - role
      title: CreateMsgReq
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
      example:
        detail:
          - loc:
              - body
              - name
            msg: Field required
            type: missing
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````