Python SDK

pip install glytos

Setup

import os
from glytos import Glytos

glytos = Glytos(api_key=os.environ["GLYTOS_API_KEY"])

To act in a specific environment, name it - dev, staging, prod, or an environment uuid. Without it, requests use the organization's default environment. A value that matches no environment falls back to the default rather than failing.

prod = Glytos(api_key=os.environ["GLYTOS_API_KEY"], environment="prod")

Timeouts

timeout defaults to 30 seconds. It is passed to httpx, which applies it to each phase of a request separately - connecting, and each wait for the next bytes of the response - so a buffered text turn fails with httpx.ReadTimeout if the reply takes longer than that to arrive. A long reply can, so raise it, or pass your own httpx.Client (httpx.AsyncClient for AsyncGlytos) as http_client:

glytos = Glytos(api_key=os.environ["GLYTOS_API_KEY"], timeout=120.0)

A stream is only cut off if the gap between two events exceeds the timeout.

Text conversations

A thread holds a conversation; a run is one turn on it. The reply is in the result - there is no run to poll. See Chat.

thread = glytos.threads.create(agent=agent_uuid)
run = glytos.threads.runs.create(thread, "What are your opening hours?")

# Or stream it as it is written
for event in glytos.threads.runs.stream(thread, "Summarise the policy"):
    if event.type == "token":
        print(event.delta, end="", flush=True)

agents is an alias of workflows: the product calls them agents, the API path is /workflows. Either works.

Resources

glytos.workflows.list()
glytos.workflows.retrieve(workflow_uuid)
glytos.workflows.create(name="Receptionist", mode="prompt")

glytos.calls.create(transport="phone", workflow_uuid=workflow_uuid, to_number="+1...")
glytos.calls.list()
glytos.calls.control(call_uuid, action="say", text="One moment, please.")

glytos.workflows.session(workflow_uuid, session_uuid)

The client covers agents (alias workflows), threads, folders, imports, chat, calls, phone_numbers, sip_trunks, campaigns, dnc, sessions, webhooks, tools, knowledge_base, vector_stores, integrations, automations, test_suites, analytics, billing, environments, providers, api_keys and organizations. An AsyncGlytos client mirrors the same surface with await, and async for over a stream.

Anything not wrapped

glytos.request("GET", "/audit")

Verifying webhooks

from glytos import verify_webhook

# `raw_body` must be the untouched request body - parsing and re-serialising it
# changes the bytes and the signature will not match.
ok = verify_webhook(raw_body, request.headers["X-Glytos-Signature"], secret)

See Webhooks.