---
title: "Create a chat completion"
method: POST
path: "/ai/chat/completions"
tags: ["Chat"]
deprecated: true
---

# Create a chat completion

`POST /ai/chat/completions`

> **Deprecated.**

**Deprecated**: Use `POST /v2/ai/openai/chat/completions` instead. Chat with a language model. This endpoint is consistent with the [OpenAI Chat Completions API](https://platform.openai.com/docs/api-reference/chat) and may be used with the OpenAI JS or Python SDK.

## Request body

- ChatCompletionRequest
  - `messages` ChatCompletionSystemMessageParam[], required — A list of the previous chat messages for context.
    - `content` union, required
      - string
      - object[]
        - `type` 'text' | 'image_url', required
        - `text` string
        - `image_url` string
    - `role` 'system' | 'user' | 'assistant' | 'tool', required
  - `model` string — The language model to chat with.
  - `service_tier` string — The service tier to use for this request. Supported values vary by model; use `GET /v2/ai/openai/models` and inspect the model's `service_tiers` field. If omitted, Telnyx-hosted models use `default`.
  - `api_key_ref` string — If you are using an external inference provider like xAI or OpenAI, this field allows you to pass along a reference to your API key. After creating an [integration secret](https://developers.telnyx.com/api-reference/integration-secrets/create-a-secret) for you API key, pass the secret's `identifier` in this field.
  - `stream` boolean — Whether or not to stream data-only server-sent events as they become available.
  - `temperature` number — Adjusts the "creativity" of the model. Lower values make the model more deterministic and repetitive, while higher values make the model more random and creative.
  - `max_tokens` integer — Maximum number of completion tokens the model should generate.
  - `tools` union[] — The `function` tool type follows the same schema as the [OpenAI Chat Completions API](https://platform.openai.com/docs/api-reference/chat). The `retrieval` tool type is unique to Telnyx. You may pass a list of [embedded storage buckets](https://developers.telnyx.com/api-reference/embeddings/embed-documents) for retrieval-augmented generation.
    - union
      - ChatCompletionToolParam
        - `type` 'function', required
        - `function` FunctionDefinition, required
          - `name` string, required
          - `description` string
          - `parameters` object
      - Retrieval
        - `type` 'retrieval', required
        - `retrieval` BucketIds, required
          - `bucket_ids` string[], required — List of [embedded storage buckets](https://developers.telnyx.com/api-reference/embeddings/embed-documents) to use for retrieval-augmented generation.
          - `max_num_results` integer — The maximum number of results to retrieve as context for the language model.
  - `tool_choice` 'none' | 'auto' | 'required'
  - `response_format` ChatCompletionResponseFormatParam
    - `type` 'text' | 'json_object', required
  - `guided_json` object — Must be a valid JSON schema. If specified, the output will follow the JSON schema.
  - `guided_regex` string — If specified, the output will follow the regex pattern.
  - `guided_choice` string[] — If specified, the output will be exactly one of the choices.
  - `min_p` number — This is an alternative to `top_p` that [many prefer](https://github.com/huggingface/transformers/issues/27670). Must be in [0, 1].
  - `n` number — This will return multiple choices for you instead of a single chat completion.
  - `use_beam_search` boolean — Setting this to `true` will allow the model to [explore more completion options](https://huggingface.co/blog/how-to-generate#beam-search). This is not supported by OpenAI.
  - `best_of` integer — This is used with `use_beam_search` to determine how many candidate beams to explore.
  - `length_penalty` number — This is used with `use_beam_search` to prefer shorter or longer completions.
  - `early_stopping` boolean — This is used with `use_beam_search`. If `true`, generation stops as soon as there are `best_of` complete candidates; if `false`, a heuristic is applied and the generation stops when is it very unlikely to find better candidates.
  - `logprobs` boolean — Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`.
  - `top_logprobs` integer — This is used with `logprobs`. An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability.
  - `frequency_penalty` number — Higher values will penalize the model from repeating the same output tokens.
  - `presence_penalty` number — Higher values will penalize the model from repeating the same output tokens.
  - `top_p` number — An alternative or complement to `temperature`. This adjusts how many of the top possibilities to consider.
  - `stop` union — Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
    - string
    - string[]
  - `seed` integer — If specified, the system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
  - `enable_thinking` boolean — Whether to enable the thinking/reasoning phase for models that support it (e.g., QwQ, Qwen3). When set to false, the model will skip the internal reasoning step and respond directly, which can reduce latency. Defaults to true.

## Response `200`

Successful Response

- object

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/team-telnyx/apis/telnyx-api-2.md) · [All operations](https://skmtc.net/team-telnyx/apis/telnyx-api-2/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/team-telnyx/telnyx-api-2/revisions/8f5f4e537994/schema)
