"""Quickstart: the smallest program that gets an LLM responding through the
Tetrate Agent Router (TARS) Python SDK. You bring an API key; the SDK lists the
catalog and uses the first available model. Override with
AGENTROUTER_QUICKSTART_MODEL. Customer and project are derived from the API
key's session -- nothing to pass.

Prerequisites (set in the environment):

    AGENTROUTER_API_KEY    a long-lived key (looks like <keyid>.<secret>) for an existing project
    AGENTROUTER_BASE_URL   optional; defaults to https://api.tetrate.ai

The prompt itself is in the code below -- edit it to ask your own question.
Install and run (from the repo root):

    pip install -e sdks/python
    python sdks/examples/python/quickstart/quickstart.py

After installing the SDK sdist, the bundled copy lives next to the package at
examples/quickstart -- run `python examples/quickstart/quickstart.py` from the
extracted tree.
"""

from __future__ import annotations

import os

from agentrouter_sdk import Client


def main() -> None:
    # Client picks up AGENTROUTER_API_KEY and AGENTROUTER_BASE_URL from the
    # environment by default.
    with Client(api_key=os.environ["AGENTROUTER_API_KEY"]) as router:
        # Pick the model. The inference handler requires a non-empty model, so
        # when AGENTROUTER_QUICKSTART_MODEL is unset we list the catalog and use
        # the first model's bare name (e.g. claude-haiku-4-5), which resolves
        # its provider server-side.
        model = os.environ.get("AGENTROUTER_QUICKSTART_MODEL", "")
        if not model:
            models = router.catalog.list_models().models
            if not models:
                raise RuntimeError(
                    "no models in catalog -- ask an admin to import a catalog bundle"
                )
            model = models[0].name

        # Edit this prompt to ask your own question.
        prompt = "Happy happy joy joy"

        # Customer and project default from the session backing the API key;
        # pass "" to let the server resolve them.
        res = router.inference.prompt("", "", prompt, model=model)

    print(f"model:      {res.model}")
    print(f"completion: {res.completion}")
    print(f"tokens:     {res.prompt_tokens} prompt / {res.completion_tokens} completion")


if __name__ == "__main__":
    main()
