Skip to main content

LLMGateway Python SDK Client

Project description

LLMGateway Python SDK

LLMGateway Logo

A Python SDK for interacting with the LLMGateway API.

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.0.tar.gz (8.4 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.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llmgateway_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 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.0.tar.gz
Algorithm Hash digest
SHA256 3892286da2d9a7b002cc6a621fdc925810fd725aa892f1d027f8a4c786cb1cc7
MD5 caff318279d44239ebc259290699b72c
BLAKE2b-256 d319ec0cf6e7eea85cc9b238369ec2f25eaf3c89e34cc8aaa11661b48abdf82c

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmgateway_sdk-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: llmgateway_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7281f9bb28e819b5fb1d7d43738e887ea86f113dca62da3384bee1c2ea329fe
MD5 e9bf9ddb7c77cb8ad74a59d0eda2acf1
BLAKE2b-256 41e2e89bf98dc7af9c40b8317147b48a53c44fa837eca1acce15354b76b4200b

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmgateway_sdk-0.1.0-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