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-sdk

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.1.tar.gz (15.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.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llmkit_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 15.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.1.tar.gz
Algorithm Hash digest
SHA256 9b4b1362774822d6f40b578354df6a13c03913daec1629ad79a8c65d506378e3
MD5 b8d9425e55fa50a47776c17189debc2d
BLAKE2b-256 ac4be9248b58b679cd966b98670c5db6e3906c1abc66a7cae5cc9b1897577e05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llmkit_sdk-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40d5caa7383ac1f7cf15a090e6e2208a121d7860095a0b055837eafedf751fc2
MD5 5c63954b076fc62532f48e517d523ae0
BLAKE2b-256 c5dac3f8f9b94a0b564a397749e180ae1237acb4bacf0397acc96139fedafd62

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