Skip to main content

Prerequisites

Install the OpenAI SDK:
pip install openai
The Inference API is OpenAI-compatible. Any OpenAI SDK works with a base_url swap.

Python

import os
from openai import OpenAI

client = OpenAI(
  api_key=os.getenv("TELNYX_API_KEY"),
  base_url="https://api.telnyx.com/v2/ai/openai",
)

chat_completion = client.chat.completions.create(
  messages=[
    {"role": "user", "content": "Tell me about Telnyx"}
  ],
  model="moonshotai/Kimi-K2.5",
  stream=True
)

for chunk in chat_completion:
  if chunk.choices[0].delta.content:
    print(chunk.choices[0].delta.content, end="", flush=True)

Core Concepts

Messages

Chat history passed to the model.

Roles

Every message has a role: system, user, assistant, or tool.
  • system — model behavior instructions
  • user — end-user input
  • assistant — model output
  • tool — function call results. See Function Calling.

Models

Available Models lists all hosted LLMs with context lengths and capabilities.

Streaming

Server-sent events, same as OpenAI.

What Next?

I want to…Go to
Build a voice assistantNo-Code Voice Assistant
Call custom code from the modelFunction Calling / Streaming Functions
Ground responses in documentsEmbeddings
Identify themes in dataClusters
Migrate from OpenAIOpenAI Migration
Browse all modelsAvailable Models