Chat Completions Quickstart
Sign up for a Telnyx mission control portal account
If you haven't already, head to telnyx.com/sign-up to sign up for your free Telnyx account. It’ll give you access to our Mission Control Portal where you can chat with language models running on Telnyx in the AI Playground.
You can use the system prompt to give context and instructions before asking a question to a model. For example, users can specify a role, how to personalize the response, or what tone to use.
You can also choose from a variety of open-source models or pass us your OpenAI API key to use their models. For the open source models:
- If you are optimizing for speed + price, try meta-llama/Meta-Llama-3-8B-Instruct
- For quality, try meta-llama/Meta-Llama-3-70B-Instruct
- For a balance, try NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO
Video Demonstration using System Prompts and AI Storage
You can also use AI-enabled Telnyx Storage buckets to provide context that won't fit in the system prompt. We will cover this in more detail in a future tutorial.
Using the API
You can also use our OpenAI-compatible chat completions API to interact programmatically with a language model.
Getting a v2 API Key
You can create a v2 API Key using these instructions.
Python Example
Here is some simple Python to stream a chat response using Telnyx.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("TELNYX_API_KEY"),
base_url="https://api.telnyx.com/v2/ai",
)
chat_completion = client.chat.completions.create(
messages=[{
"role": "user",
"content": "Can you explain 10DLC to me?"
}],
model="NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
stream=True
)
for chunk in chat_completion:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)