Loading...
Loading...
Access Telnyx LLM inference APIs, embeddings, and AI analytics for call insights and summaries. This skill provides Python SDK examples.
npx skill4agent add team-telnyx/telnyx-ext-agent-skills telnyx-ai-inference-pythonpip install telnyximport os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)clientGET /ai/conversationsconversations = client.ai.conversations.list()
print(conversations.data)POST /ai/conversationsmetadatanameconversation = client.ai.conversations.create()
print(conversation.id)GET /ai/conversations/insight-groupspage = client.ai.conversations.insight_groups.retrieve_insight_groups()
page = page.data[0]
print(page.id)POST /ai/conversations/insight-groupsnamedescriptionwebhookinsight_template_group_detail = client.ai.conversations.insight_groups.insight_groups(
name="name",
)
print(insight_template_group_detail.data)GET /ai/conversations/insight-groups/{group_id}insight_template_group_detail = client.ai.conversations.insight_groups.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(insight_template_group_detail.data)PUT /ai/conversations/insight-groups/{group_id}descriptionnamewebhookinsight_template_group_detail = client.ai.conversations.insight_groups.update(
group_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(insight_template_group_detail.data)DELETE /ai/conversations/insight-groups/{group_id}client.ai.conversations.insight_groups.delete(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)POST /ai/conversations/insight-groups/{group_id}/insights/{insight_id}/assignclient.ai.conversations.insight_groups.insights.assign(
insight_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
group_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)DELETE /ai/conversations/insight-groups/{group_id}/insights/{insight_id}/unassignclient.ai.conversations.insight_groups.insights.delete_unassign(
insight_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
group_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)GET /ai/conversations/insightspage = client.ai.conversations.insights.list()
page = page.data[0]
print(page.id)POST /ai/conversations/insightsinstructionsnamejson_schemawebhookinsight_template_detail = client.ai.conversations.insights.create(
instructions="instructions",
name="name",
)
print(insight_template_detail.data)GET /ai/conversations/insights/{insight_id}insight_template_detail = client.ai.conversations.insights.retrieve(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(insight_template_detail.data)PUT /ai/conversations/insights/{insight_id}instructionsjson_schemanamewebhookinsight_template_detail = client.ai.conversations.insights.update(
insight_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
print(insight_template_detail.data)DELETE /ai/conversations/insights/{insight_id}client.ai.conversations.insights.delete(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)GET /ai/conversations/{conversation_id}conversation = client.ai.conversations.retrieve(
"conversation_id",
)
print(conversation.data)PUT /ai/conversations/{conversation_id}metadataconversation = client.ai.conversations.update(
conversation_id="conversation_id",
)
print(conversation.data)DELETE /ai/conversations/{conversation_id}client.ai.conversations.delete(
"conversation_id",
)GET /ai/conversations/{conversation_id}/conversations-insightsresponse = client.ai.conversations.retrieve_conversations_insights(
"conversation_id",
)
print(response.data)POST /ai/conversations/{conversation_id}/messagerolecontentmetadatanamesent_attool_call_idtool_callstool_choiceclient.ai.conversations.add_message(
conversation_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
role="role",
)GET /ai/conversations/{conversation_id}/messagesmessages = client.ai.conversations.messages.list(
"conversation_id",
)
print(messages.data)queuedprocessingfailedsuccesspartial_successGET /ai/embeddingsembeddings = client.ai.embeddings.list()
print(embeddings.data)POST /ai/embeddingsbucket_namedocument_chunk_overlap_sizedocument_chunk_sizeembedding_modelloaderembedding_response = client.ai.embeddings.create(
bucket_name="bucket_name",
)
print(embedding_response.data)GET /ai/embeddings/bucketsbuckets = client.ai.embeddings.buckets.list()
print(buckets.data)GET /ai/embeddings/buckets/{bucket_name}bucket = client.ai.embeddings.buckets.retrieve(
"bucket_name",
)
print(bucket.data)DELETE /ai/embeddings/buckets/{bucket_name}client.ai.embeddings.buckets.delete(
"bucket_name",
)num_docsPOST /ai/embeddings/similarity-searchbucket_namequerynum_of_docsresponse = client.ai.embeddings.similarity_search(
bucket_name="bucket_name",
query="query",
)
print(response.data)POST /ai/embeddings/urlurlbucket_nameembedding_response = client.ai.embeddings.url(
bucket_name="bucket_name",
url="url",
)
print(embedding_response.data)GET /ai/embeddings/{task_id}embedding = client.ai.embeddings.retrieve(
"task_id",
)
print(embedding.data)GET /ai/clusterspage = client.ai.clusters.list()
page = page.data[0]
print(page.task_id)POST /ai/clustersbucketfilesmin_cluster_sizemin_subcluster_sizeprefixresponse = client.ai.clusters.compute(
bucket="bucket",
)
print(response.data)GET /ai/clusters/{task_id}cluster = client.ai.clusters.retrieve(
task_id="task_id",
)
print(cluster.data)DELETE /ai/clusters/{task_id}client.ai.clusters.delete(
"task_id",
)GET /ai/clusters/{task_id}/graphresponse = client.ai.clusters.fetch_graph(
task_id="task_id",
)
print(response)
content = response.read()
print(content)POST /ai/audio/transcriptionsresponse = client.ai.audio.transcribe(
model="distil-whisper/distil-large-v2",
)
print(response.text)POST /ai/chat/completionsmessagesapi_key_refbest_ofearly_stoppingfrequency_penaltyguided_choiceguided_jsonguided_regexlength_penaltylogprobsmax_tokensmin_pmodelnpresence_penaltyresponse_formatstreamtemperaturetool_choicetoolstop_logprobstop_puse_beam_searchresponse = client.ai.chat.create_completion(
messages=[{
"role": "system",
"content": "You are a friendly chatbot.",
}, {
"role": "user",
"content": "Hello, world!",
}],
)
print(response)GET /ai/fine_tuning/jobsjobs = client.ai.fine_tuning.jobs.list()
print(jobs.data)POST /ai/fine_tuning/jobsmodeltraining_filehyperparameterssuffixfine_tuning_job = client.ai.fine_tuning.jobs.create(
model="model",
training_file="training_file",
)
print(fine_tuning_job.id)job_idGET /ai/fine_tuning/jobs/{job_id}fine_tuning_job = client.ai.fine_tuning.jobs.retrieve(
"job_id",
)
print(fine_tuning_job.id)POST /ai/fine_tuning/jobs/{job_id}/cancelfine_tuning_job = client.ai.fine_tuning.jobs.cancel(
"job_id",
)
print(fine_tuning_job.id)POST /ai/openai/embeddingsinputmodeldimensionsencoding_formatuserresponse = client.ai.openai.embeddings.create_embeddings(
input="The quick brown fox jumps over the lazy dog",
model="thenlper/gte-large",
)
print(response.data)GET /ai/openai/embeddings/modelsresponse = client.ai.openai.embeddings.list_embedding_models()
print(response.data)GET /ai/modelsresponse = client.ai.retrieve_models()
print(response.data)POST /ai/summarizebucketfilenamesystem_promptresponse = client.ai.summarize(
bucket="bucket",
filename="filename",
)
print(response.data)