Skip to main content

LLMGateway Python SDK Client

Project description

LLMGateway Python SDK

LLMGateway Logo

A Python SDK for interacting with the LLMGateway API.


Project Status
CI  CI  Pre-commit  Codecov
Meta  Package version  Pydantic Version 2  Ruff

Installation

# using pip
pip install llmgateway-sdk

# using uv
uv pip install llmgateway-sdk

# using poetry
poetry add llmgateway-sdk

Usage

Basic Usage

from llmgateway import LLMGatewayClient, ChatCompletionRequest, Message

# Initialize the client
client = LLMGatewayClient(api_key="your-api-key")

# Create a chat completion request
request = ChatCompletionRequest(
    model="gpt-4",
    messages=[
        Message(role="user", content="Hello!")
    ]
)

# Get a completion
response = client.chat_completions(request)
print(response.message)

# List available models
models = client.list_models()
for model in models.data:
    print(f"Model: {model.name} (ID: {model.id})")

Async Usage

import asyncio
from llmgateway import LLMGatewayClient, ChatCompletionRequest, Message

async def main():
    client = LLMGatewayClient(api_key="your-api-key")

    request = ChatCompletionRequest(
        model="gpt-4",
        messages=[
            Message(role="user", content="Hello!")
        ]
    )

    # Get a completion asynchronously
    response = await client.achat_completions(request)
    print(response.message)

    # List models asynchronously
    models = await client.alist_models()
    for model in models.data:
        print(f"Model: {model.name} (ID: {model.id})")

    # Don't forget to close the client
    await client.aclose()

asyncio.run(main())

Streaming Responses

from llmgateway import LLMGatewayClient, ChatCompletionRequest, Message

client = LLMGatewayClient(api_key="your-api-key")

request = ChatCompletionRequest(
    model="gpt-4",
    messages=[
        Message(role="user", content="Tell me a story")
    ],
    stream=True
)

# Get streaming responses
for response in client.chat_completions(request):
    print(response.message, end="", flush=True)

Features

  • Synchronous and asynchronous API support
  • Streaming responses
  • Type hints and validation using Pydantic
  • Comprehensive test coverage
  • Modern Python packaging with pyproject.toml

License

MIT License

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

llmgateway_sdk-0.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

llmgateway_sdk-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llmgateway_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llmgateway_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 180786ac838be563a1d3607033fee98592c2d96f2aa3d37508ef65c7efa644cd
MD5 a2cf24a38e32e97e8dd197ac7f2b9c9b
BLAKE2b-256 8719c37730132a69deae2eaba95aea29efe1c0c54e2e63728d22e0b3b6a276cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmgateway_sdk-0.1.1.tar.gz:

Publisher: release.yaml on yezz123/llmgateway-py-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: llmgateway_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llmgateway_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 19308b96110e65ee946e70ecb984f39c031dc5a8f841aad1c921633f0e8aa369
MD5 7f72c3d1fcc4bddada11d6e2edcc4f43
BLAKE2b-256 7215b47ad7827a1ccb32167215ecce78cae5ee78a9fe4af0f4e385ad8e116759

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmgateway_sdk-0.1.1-py3-none-any.whl:

Publisher: release.yaml on yezz123/llmgateway-py-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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