OpenAI Chat

Create a chat completion (OpenAI-compatible)

Chat with a language model. This endpoint is consistent with the OpenAI Chat Completions API and may be used with the OpenAI JS or Python SDK by setting the base URL to https://api.telnyx.com/v2/ai/openai.

post/ai/openai/chat/completions

Request body

modelstring

The language model to chat with.

service_tierstring

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.

region'USA' | 'EU' | 'AUS' | 'UAE'

Optional data-residency region the request should be served from, using the same vocabulary as your account's Data Locality setting. Behavior depends on mode. Supported for Telnyx-hosted models only: a request routed to an external provider never passes through Telnyx model routing, so a region cannot be enforced for it. Omit for today's latency-based routing.

mode'preferred' | 'strict'

How strictly region is applied. preferred (the default when region is set) tries that region first and falls back to another when the model cannot be served there, so a request that would have succeeded still succeeds. strict pins the request: it is served from that region or it fails with a 422, never redirected to another region. Requires region.

api_key_refstring

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 for you API key, pass the secret's identifier in this field.

streamboolean

Whether or not to stream data-only server-sent events as they become available.

temperaturenumber

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_tokensinteger nullable

Maximum number of completion (output) tokens the model may generate per request. Defaults to 8192 when omitted or null. Set a higher value to allow longer completions. The model's max_completion_tokens metadata (see GET /ai/models), when set, caps both the default and any larger explicit value. Reasoning models consume this budget across reasoning and answer tokens combined.

tool_choice'none' | 'auto' | 'required'
min_pnumber

This is an alternative to top_p that many prefer. Must be in [0, 1].

nnumber

This will return multiple choices for you instead of a single chat completion.

use_beam_searchboolean

Setting this to true will allow the model to explore more completion options. This is not supported by OpenAI.

best_ofinteger

This is used with use_beam_search to determine how many candidate beams to explore.

length_penaltynumber

This is used with use_beam_search to prefer shorter or longer completions.

early_stoppingboolean

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.

logprobsboolean

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_logprobsinteger

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_penaltynumber

Higher values will penalize the model from repeating the same output tokens.

presence_penaltynumber

Higher values will penalize the model from repeating the same output tokens.

top_pnumber

An alternative or complement to temperature. This adjusts how many of the top possibilities to consider.

seedinteger

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_thinkingboolean

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.

reasoning_effort'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'

Controls the reasoning effort for models that support it. When set, the model spends more or less compute on internal reasoning before generating its response. Supported values: none, minimal, low, medium, high, xhigh, max. Not all models support all values; unsupported values are rejected with a 400 error. When omitted, reasoning models use their default effort level.

Example request

{
  "messages": [
    {
      "role": "system",
      "content": "You are a friendly chatbot."
    },
    {
      "role": "user",
      "content": "Hello, world!"
    }
  ]
}

Response

Successful Response

object required

Changes

Changed in 3 of the 99 revisions of this API.147

    • ○

      the request property became nullable

      request-property-became-nullable

    • ○

      the request property default value 8192 was added

      request-property-default-value-added

  • a6a61a29ecdd144See the full diff
    • ▲

      the request property type changed from object to no type

      request-property-type-changed

    • ●

      removed the request property

      request-property-removed

    • ●

      removed the request property

      request-property-removed

    • ●

      removed the request property

      request-property-removed

    • ●

      removed the request property /

      request-property-removed

    • ○

      added the new optional request property

      new-optional-request-property

    • ○

      added the new optional request property

      new-optional-request-property

    • ○

      added the new optional request property

      new-optional-request-property

    • ○

      added to the request property oneOf list

      request-property-one-of-added

    This revision also has 34 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog

    • ○

      added the new optional request property

      new-optional-request-property

Of the 99 revisions, 1 has no diff computed.