Skip to main content
The Telnyx Inference API accepts OpenAI-compatible chat completion requests. Use a Telnyx API key and the SDK base URL https://api.telnyx.com/v2/ai/openai.

Prerequisites

1. Set your API key

Replace the placeholder with the Telnyx API key. Run this in the same terminal used for the requests below:
Keep the key on the server or in a local environment variable. Do not commit it to source control or include it in browser or mobile application code.

2. Send a chat completion

These examples use zai-org/GLM-5.3-Flash. See Available Models for model IDs and capabilities, or list models through the API.
Run this in a macOS or Linux shell. No SDK installation is required:
A successful request returns JSON with the answer in choices[0].message.content. The usage object reports token counts. The answer text varies between requests.
The SDK base URL ends in /openai; the full HTTP endpoint ends in /openai/chat/completions. See the Chat Completions API reference for all request parameters and response fields.

3. Stream the response (optional)

In quickstart.py, keep the imports and client setup, then replace the request and final print with this code. Run python quickstart.py again:
Reasoning models can return reasoning_content separately from the final answer in content: on message for a non-streaming response, or delta when streaming. Models without reasoning omit this field. The example prints both separately so the reasoning phase does not appear silent. Omit the reasoning print block to display only the answer in an application.
The examples use the model’s default reasoning effort. Set reasoning_effort only to a value supported by the selected model; unsupported values return an error.

Troubleshooting

Continue the conversation

Send prior turns in messages to preserve context. Use system for model instructions, user for input, assistant for previous responses, and tool for function results. See Function Calling to connect the model to application code.

What Next?