Skip to content

Python: Add Telnyx provider samples (OpenAI-compatible endpoint)#5926

Draft
gbattistel wants to merge 5 commits into
microsoft:mainfrom
team-telnyx:feature/telnyx-provider-sample
Draft

Python: Add Telnyx provider samples (OpenAI-compatible endpoint)#5926
gbattistel wants to merge 5 commits into
microsoft:mainfrom
team-telnyx:feature/telnyx-provider-sample

Conversation

@gbattistel
Copy link
Copy Markdown

@gbattistel gbattistel commented May 18, 2026

Motivation and Context

Telnyx provides an OpenAI-compatible API endpoint (https://api.telnyx.com/v2/ai/openai) that supports chat completions and embeddings. Adding provider samples makes it easy for Telnyx users (and anyone using OpenAI-compatible endpoints) to get started with Agent Framework.

Related issue: #5925

Description

Adds three files under python/samples/02-agents/providers/telnyx/:

  • telnyx_chat_completion.py — Chat completion sample using OpenAIChatClient with a custom base_url. Demonstrates both streaming and non-streaming responses.
  • telnyx_embeddings.py — Embeddings sample using OpenAIEmbeddingClient with a custom base_url.
  • README.md — Setup instructions, environment variables, and quick start guide.

This follows the same pattern as the existing Ollama sample (ollama_with_openai_chat_client.py), where an existing provider client is configured with a custom base_url — no new provider package is needed.

Contribution Checklist

  • The code builds without errors
  • Samples follow SAMPLE_GUIDELINES.md (copyright header, module docstring, dotenv, numbered comments, sample output)
  • No new packages or dependencies required — uses existing OpenAIChatClient / OpenAIEmbeddingClient
  • README includes prerequisites, configuration, and quick start

Closes #5925

Add samples demonstrating how to use Telnyx as an OpenAI-compatible
inference provider with Agent Framework's existing OpenAIChatClient
and OpenAIEmbeddingClient.

Samples included:
- telnyx_chat_completion.py: basic chat with streaming/non-streaming
- telnyx_embeddings.py: text embeddings via Telnyx
- telnyx_chat_with_tools.py: chat with telecom tools (SMS, lookup)

Follows the same pattern as the existing Ollama provider sample.
No new provider code — just configuration of base_url and api_key.

Refs: microsoft#5925
Copilot AI review requested due to automatic review settings May 18, 2026 17:43
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels May 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Python samples demonstrating how to use Telnyx’s OpenAI-compatible endpoint (base_url) with the existing Agent Framework OpenAI clients.

Changes:

  • Added a Telnyx chat completion sample (streaming + non-streaming) using OpenAIChatClient
  • Added a Telnyx embeddings sample using OpenAIEmbeddingClient
  • Added a Telnyx provider README with setup and quick start instructions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py New Telnyx chat completion sample using a custom base_url
python/samples/02-agents/providers/telnyx/telnyx_embeddings.py New Telnyx embeddings sample using a custom base_url
python/samples/02-agents/providers/telnyx/README.md Documentation for configuring/running the Telnyx samples

Comment on lines +1 to +25
# Copyright (c) Microsoft. All rights reserved.

import asyncio
import os

from agent_framework.openai import OpenAIEmbeddingClient
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

"""
Telnyx Embeddings Example

This sample demonstrates using Telnyx for text embeddings through the
OpenAIEmbeddingClient by configuring the base_url to point to the
Telnyx AI API endpoint.

Telnyx provides an OpenAI-compatible API that supports embeddings
generation using models like `thenlper/gte-large`.

Environment Variables:
TELNYX_API_KEY — Your Telnyx API key (from https://portal.telnyx.com/)
TELNYX_EMBEDDING_MODEL — Embedding model name (default: "thenlper/gte-large")
"""
Comment on lines +10 to +28
# Load environment variables from .env file
load_dotenv()

"""
Telnyx Chat Completion Example

This sample demonstrates using Telnyx as an OpenAI-compatible inference
provider through the OpenAIChatClient by configuring the base_url to
point to the Telnyx AI API endpoint.

Telnyx provides an OpenAI-compatible API at https://api.telnyx.com/v2/ai/openai
that supports chat completions, embeddings, and function/tool calling.

Environment Variables:
TELNYX_API_KEY — Your Telnyx API key (from https://portal.telnyx.com/)
TELNYX_MODEL — Model name to use (default: "Kimi-K2.5")
Available models include: Kimi-K2.5, GLM-5.1-FP8,
MiniMax-M2.7, Qwen3-235B-A22B
"""
Comment on lines +20 to +23
| File | Description |
|------|-------------|
| [`telnyx_chat_completion.py`](telnyx_chat_completion.py) | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. |
| [`telnyx_embeddings.py`](telnyx_embeddings.py) | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. |
Comment on lines +42 to +43
# Install the Agent Framework OpenAI package
pip install agent-framework-openai
Comment on lines +18 to +23
## Examples

| File | Description |
|------|-------------|
| [`telnyx_chat_completion.py`](telnyx_chat_completion.py) | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. |
| [`telnyx_embeddings.py`](telnyx_embeddings.py) | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. |
@gbattistel
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Telnyx"

- Move module docstrings before load_dotenv() (top of file)
- Fix markdown table syntax in README (remove extra pipes)
- Add python-dotenv to Quick Start install instructions
- Update PR description to match actual file count (3 files)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

python/samples/02-agents/providers/telnyx/telnyx_embeddings.py:50

  • OpenAIEmbeddingClient.get_embeddings() returns a list of Embedding objects (with .vector / .dimensions), but this loop treats each item as a raw list[float] (len(embedding) and slicing embedding[:5]). This will raise at runtime; use embedding.dimensions (or len(embedding.vector)) and slice embedding.vector instead.
    for i, embedding in enumerate(response):
        print(f"Text {i + 1}: \"{texts[i]}\"")
        print(f"  Dimensions: {len(embedding)}")
        print(f"  Preview: [{', '.join(str(v) for v in embedding[:5])}, ...]")

python/samples/02-agents/providers/telnyx/telnyx_chat_completion.py:24

  • This imports/uses OpenAIChatClient, which calls the OpenAI Responses API (e.g., /responses). The PR description says Telnyx provides an OpenAI-compatible endpoint for chat completions, so this sample will likely fail against Telnyx unless Telnyx implements the Responses API. Consider switching to OpenAIChatCompletionClient (Chat Completions API) or clarifying the required endpoint capabilities.
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
from dotenv import load_dotenv

Comment on lines +20 to +23
| File | Description |
|------|-------------|
| `telnyx_chat_completion.py` | Basic chat completion using `OpenAIChatClient` with Telnyx endpoint. Shows both streaming and non-streaming responses. |
| `telnyx_embeddings.py` | Text embeddings using `OpenAIEmbeddingClient` with Telnyx endpoint. |
Comment on lines +3 to +7
"""Telnyx Chat Completion Example

This sample demonstrates using Telnyx as an OpenAI-compatible inference
provider through the OpenAIChatClient by configuring the base_url to
point to the Telnyx AI API endpoint.
Comment on lines +3 to +7
"""Telnyx Embeddings Example

This sample demonstrates using Telnyx for text embeddings through the
OpenAIEmbeddingClient by configuring the base_url to point to the
Telnyx AI API endpoint.
The get_embeddings() response returns Embedding objects with .dimensions
and .vector attributes, not raw lists. Using len() and slicing directly
causes TypeError at runtime.
@gbattistel
Copy link
Copy Markdown
Author

Hi! This PR is ready for review. Both samples have been tested locally and work correctly (chat completion with streaming + non-streaming, and embeddings). The Copilot feedback about the embeddings API usage has been addressed in the latest commit. Would appreciate a review when possible — @eavanvalkenburg @moonbox3 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Feature]: Add Telnyx provider sample (OpenAI-compatible endpoint)

3 participants