> ## 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 an OpenAI-compatible response

> Create a response using Telnyx's OpenAI-compatible Responses API. This endpoint is compatible with the [OpenAI Responses API](https://developers.openai.com/api/reference/responses/overview) and may be used with the OpenAI JS or Python SDK by setting the base URL to `https://api.telnyx.com/v2/ai/openai`.

The `conversation` parameter refers to a Telnyx Conversation rather than an OpenAI-hosted conversation object. To persist a thread across turns, first [create a conversation](https://developers.telnyx.com/api-reference/conversations/create-a-conversation) with `POST /ai/conversations`, then pass that conversation's `id` in the Responses request as `conversation`. The endpoint appends the new input, assistant output, reasoning, and tool-call messages to that conversation. Reuse the same `conversation` id on subsequent Responses requests, including tool-result followups, so the model receives the prior context.

If `conversation` is omitted, the request is processed without persisting messages to a Telnyx conversation. Use the Conversations API to manage history: [list conversations](https://developers.telnyx.com/api-reference/conversations/list-conversations) (optionally filtered by metadata), [fetch messages](https://developers.telnyx.com/api-reference/conversations/get-conversation-messages) for a conversation, and optionally [add messages](https://developers.telnyx.com/api-reference/conversations/create-message) outside the Responses flow.

You can attach arbitrary metadata when creating a conversation (for example to tag the conversation's source, channel, or user) and later filter by it when listing conversations.



## OpenAPI

````yaml https://telnyx-openapi-ng.s3.us-east-1.amazonaws.com/ai/inference.yml post /ai/openai/responses
openapi: 3.1.0
info:
  title: Telnyx AI Inference API
  version: 2.0.0
  description: API for AI inference, including chat completions, fine-tuning, and models.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
security:
  - bearerAuth: []
paths:
  /ai/openai/responses:
    post:
      tags:
        - OpenAI Chat
      summary: Create an OpenAI-compatible response
      description: >-
        Create a response using Telnyx's OpenAI-compatible Responses API. This
        endpoint is compatible with the [OpenAI Responses
        API](https://developers.openai.com/api/reference/responses/overview) and
        may be used with the OpenAI JS or Python SDK by setting the base URL to
        `https://api.telnyx.com/v2/ai/openai`.


        The `conversation` parameter refers to a Telnyx Conversation rather than
        an OpenAI-hosted conversation object. To persist a thread across turns,
        first [create a
        conversation](https://developers.telnyx.com/api-reference/conversations/create-a-conversation)
        with `POST /ai/conversations`, then pass that conversation's `id` in the
        Responses request as `conversation`. The endpoint appends the new input,
        assistant output, reasoning, and tool-call messages to that
        conversation. Reuse the same `conversation` id on subsequent Responses
        requests, including tool-result followups, so the model receives the
        prior context.


        If `conversation` is omitted, the request is processed without
        persisting messages to a Telnyx conversation. Use the Conversations API
        to manage history: [list
        conversations](https://developers.telnyx.com/api-reference/conversations/list-conversations)
        (optionally filtered by metadata), [fetch
        messages](https://developers.telnyx.com/api-reference/conversations/get-conversation-messages)
        for a conversation, and optionally [add
        messages](https://developers.telnyx.com/api-reference/conversations/create-message)
        outside the Responses flow.


        You can attach arbitrary metadata when creating a conversation (for
        example to tag the conversation's source, channel, or user) and later
        filter by it when listing conversations.
      operationId: chat_public_openai_responses_completions_post
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
              properties:
                model:
                  type: string
                  description: >-
                    Model identifier to use for the response, for example
                    `zai-org/GLM-5.1-FP8` or another model available from the
                    Telnyx OpenAI-compatible models endpoint.
                input:
                  description: >-
                    The input items for this turn, using the OpenAI Responses
                    API input format.
                conversation:
                  type: string
                  format: uuid
                  description: >-
                    Optional Telnyx Conversation ID from `POST
                    /ai/conversations`. When provided, Telnyx stores this turn
                    on that conversation and uses the conversation's prior
                    messages as context. Reuse the same ID for subsequent turns
                    and tool-result followups. Omit it for a non-persisted,
                    stateless response.
                instructions:
                  type: string
                  description: >-
                    Optional system/developer instructions for the model. When
                    used with a persisted `conversation`, send these on the
                    first request that creates the thread; subsequent turns can
                    rely on the stored history.
                stream:
                  type: boolean
                  description: >-
                    Set to `true` to stream Server-Sent Events, matching
                    OpenAI's Responses streaming format.
            example:
              model: zai-org/GLM-5.1-FP8
              conversation: 6a09cdc3-8948-47f0-aa62-74ac943d6c58
              instructions: You are a friendly chatbot.
              input:
                - role: user
                  content:
                    - type: input_text
                      text: Hello, world!
              stream: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      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
            });

            const response = await client.ai.openai.createResponse({
              conversation: '6a09cdc3-8948-47f0-aa62-74ac943d6c58',
              input: [{ role: 'user', content: [{ type: 'input_text', text: 'Hello, world!' }] }],
              instructions: 'You are a friendly chatbot.',
              model: 'zai-org/GLM-5.1-FP8',
              stream: true,
            });

            console.log(response);
        - 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
            )
            response = client.ai.openai.create_response(
                conversation="6a09cdc3-8948-47f0-aa62-74ac943d6c58",
                input=[{
                    "role": "user",
                    "content": [{
                        "type": "input_text",
                        "text": "Hello, world!",
                    }],
                }],
                instructions="You are a friendly chatbot.",
                model="zai-org/GLM-5.1-FP8",
                stream=True,
            )
            print(response)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\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\tresponse, err := client.AI.OpenAI.NewResponse(context.TODO(), telnyx.AIOpenAINewResponseParams{\n\t\tConversation: telnyx.String(\"6a09cdc3-8948-47f0-aa62-74ac943d6c58\"),\n\t\tInput: []any{\n\t\t\tmap[string]any{\n\t\t\t\t\"role\": \"user\",\n\t\t\t\t\"content\": []any{\n\t\t\t\t\tmap[string]any{\n\t\t\t\t\t\t\"type\": \"input_text\",\n\t\t\t\t\t\t\"text\": \"Hello, world!\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tInstructions: telnyx.String(\"You are a friendly chatbot.\"),\n\t\tModel:        telnyx.String(\"zai-org/GLM-5.1-FP8\"),\n\t\tStream:       telnyx.Bool(true),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response)\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.openai.OpenAICreateResponseParams;
            import com.telnyx.sdk.models.ai.openai.OpenAICreateResponseResponse;

            public final class Main {
                private Main() {}

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

                    OpenAICreateResponseResponse response = client.ai().openai().createResponse();
                }
            }
        - lang: Ruby
          source: |-
            require "telnyx"

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

            response = telnyx.ai.openai.create_response

            puts(response)
        - 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 {
              $response = $client->ai->openai->createResponse(
                conversation: '6a09cdc3-8948-47f0-aa62-74ac943d6c58',
                input: [
                  [
                    'role' => 'user',
                    'content' => [['type' => 'input_text', 'text' => 'Hello, world!']],
                  ],
                ],
                instructions: 'You are a friendly chatbot.',
                model: 'zai-org/GLM-5.1-FP8',
                stream: true,
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx ai:openai create-response \
              --api-key 'My API Key'
components:
  schemas:
    HTTPValidationError:
      title: HTTPValidationError
      type: object
      properties:
        detail:
          title: Detail
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
    ValidationError:
      title: ValidationError
      required:
        - loc
        - msg
        - type
      type: object
      properties:
        loc:
          title: Location
          type: array
          items:
            anyOf:
              - type: string
              - type: integer
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````