Skip to main content

Minimal universal LLM interface API

Project description

Toki

A minimal python library for talking to LLMs.

When using this library, in most cases one can simply switch the model name (e.g. 'openai/gpt-5' -> 'google/gemini-2.5-pro') and everything will just work.

Getting Started

pip install toki
from toki import Model, Agent, get_openrouter_api_key
from easyrepl import REPL

agent = Agent(
    Model('openai/gpt-5', get_openrouter_api_key())
)

for query in REPL():
    agent.add_user_message(query)
    for chunk in agent.execute(stream=True):
        print(chunk, end='', flush=True)
    print()

Features

  • Model: stateless class for talking to LLMs. includes blocking and streaming
  • Agent: class for maintaining conversation history when talking with a model
  • StateMachine/ClassStateMachine: tools for easily implementing complex agentic interaction scenarios

Backends

The primary backend is OpenRouter which provides REST API access to all major LLM models on the market

Issues

OpenAI models fail to work with tools

  • TODO: consider adding a separate backend just for openai. also consider adding a text only tools interface to skip around the issue

Dev

Rebuild models list file

toki-fetch-models
  • TODO: look into making this step part of the github action for publishing new version (or periodically checking the models list and auto updating/building new versions)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toki-0.2.6rc1.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toki-0.2.6rc1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file toki-0.2.6rc1.tar.gz.

File metadata

  • Download URL: toki-0.2.6rc1.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.18

File hashes

Hashes for toki-0.2.6rc1.tar.gz
Algorithm Hash digest
SHA256 21e423196f9d6b97df68ba97207fcaacf7a2da3973c00474e48b5cde8ec353a8
MD5 684da10b9cd98187907fa43fc0c0de6c
BLAKE2b-256 ddd14b489c944815cb2d195b51a8a944900b3d99c04fdb3a6942bf4eb60efa42

See more details on using hashes here.

File details

Details for the file toki-0.2.6rc1-py3-none-any.whl.

File metadata

  • Download URL: toki-0.2.6rc1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.18

File hashes

Hashes for toki-0.2.6rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 85769e73ecb72098ecf58e52b46ae9837007ccfa429a72e77c60e8fbdfe8ca88
MD5 c17f78c6279745eddb7ceb06dfe19c0d
BLAKE2b-256 0c27469a6e1a59467cfbe3f9db8912e6ff157533d3f2e81e8514150a249e9ef4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page