Skip to main content

AI API gateway SDK with cost tracking, budget enforcement, and multi-provider routing for LLM applications

Project description

llmkit

Python SDK for LLMKit, the AI API gateway with cost tracking and budget enforcement.

Install

pip install llmkit

Quick start

from llmkit import LLMKit

client = LLMKit(api_key="llmk_...")
completion, cost = client.chat(
    model="gpt-4o",
    messages=[{"role": "user", "content": "hello"}],
)

print(completion.choices[0].message.content)
print(f"Cost: ${cost.total_cost:.4f} via {cost.provider}")

Session tracking

Group costs by agent run using sessions:

agent = client.session()

for task in tasks:
    completion, cost = agent.chat(
        model="gpt-4o",
        messages=[{"role": "user", "content": task}],
    )

print(f"Session total: ${agent.stats.total_cost:.4f}")
print(f"Requests: {agent.stats.request_count}")

Bring your own provider key

client = LLMKit(
    api_key="llmk_...",
    provider_key="sk-...",
)

Escape hatch

The underlying OpenAI client is always accessible for anything the SDK doesn't cover:

stream = client.openai.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "hello"}],
    stream=True,
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Async

from llmkit import AsyncLLMKit

client = AsyncLLMKit(api_key="llmk_...")
completion, cost = await client.chat(
    model="gpt-4o",
    messages=[{"role": "user", "content": "hello"}],
)

No SDK needed

LLMKit works with any OpenAI-compatible client. No pip install required:

from openai import OpenAI

client = OpenAI(
    base_url="https://llmkit-proxy.smigolsmigol.workers.dev/v1",
    api_key="llmk_...",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "hello"}],
)

License

MIT

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

llmkit_sdk-0.1.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

llmkit_sdk-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file llmkit_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: llmkit_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for llmkit_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5024121738825141a1779b49c259277be7ee5a603cf59c0b76951610c60edb5b
MD5 65ca21d5339042a8431b69158b69cd9f
BLAKE2b-256 f9d8feb5e93cc2d8d9bf3066b321f9d22f5f5f66956e8e35bd31c00d91b99433

See more details on using hashes here.

File details

Details for the file llmkit_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llmkit_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for llmkit_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75438f8594c12a43ecb432018ecea710e67791f364aa5b12af886b5fcc936c08
MD5 1925dfe7e1b01fc8602daeebd0a40d56
BLAKE2b-256 a44bf3afba89cabf948ae026a719e95fc4209f6272b9d86e33ffb972f41fb5b9

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