Skip to main content

Unified LLM client. Currently supports Openai, Azure Openai and Google Gemini

Project description

llm-client

PyPI version
Python Version

llm-client is a unified async Python client for interacting with multiple LLM providers, including OpenAI, Azure OpenAI, and Google Gemini.
It supports single calls, structured JSON outputs, and batch processing, designed for production-ready, reusable code in applications, scripts, or pipelines.


Features

  • Async support for multiple LLM providers
  • Unified interface across OpenAI, Azure, and Google Gemini
  • Structured JSON responses via schemas
  • Retry and timeout handling
  • Batch processing support
  • Environment variable configuration for API keys
  • Easy integration into existing projects or monorepos

Installation

# Install from PyPI
pip install llm-client

Or install editable version during development:

# From project root
pip install -e .

Configuration

llm-client supports three configuration modes:

1️⃣ Config file (.cfg)

Example: llmconfig.cfg

[default_settings]
provider = openai
model = gpt-4.1-mini

[prod]
provider = openai
model = gpt-4.1
model_batch = gpt-4.1-mini

Usage:

from llm_client import LLM

llm = LLM("prod", config_file_path="llmconfig.cfg")

2️⃣ Config dictionary (for tests / CI)

from llm_client import LLM

llm = LLM(
    "default",
    config={
        "default_settings": {
            "provider": "openai",
            "model": "gpt-4.1-mini"
        }
    }
)

3️⃣ Environment variable fallback

export LLM_PROVIDER=openai
export LLM_MODEL=gpt-4.1-mini
export OPENAI_API_KEY=sk-...
llm = LLM("default")

Usage

Single async call

import asyncio
from ehs_llm_client import LLM

async def main():
    llm = LLM("prod")
    messages = [{"role": "user", "content": "Say hello in JSON"}]

    response, in_tokens, out_tokens = await llm.get_response_async(
        messages, schema="return json"
    )

    print(response)

asyncio.run(main())

Batch request

batch_line = llm.create_batch_request(
    custom_id="test1",
    messages=[{"role": "user", "content": "Give me a JSON object"}],
    schema="return json"
)

batch_id = await llm.run_batch_process([batch_line], submission_id="batch123")
status = await llm.get_batch_status(batch_id)
print(status)

API Key Management

Keep API keys out of code. Recommended environment variables:

Provider Env var name
OpenAI OPENAI_API_KEY
Azure OpenAI AZURE_OPENAI_API_KEY
Google Gemini GOOGLE_API_KEY

Development

# Create a virtual environment
python -m venv .venv
source .venv/bin/activate  # macOS/Linux
.venv\Scripts\activate     # Windows

# Install dependencies
pip install -e .

License

MIT License © 2026 Your Name

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

ehs_llm_client-0.1.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

ehs_llm_client-0.1.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file ehs_llm_client-0.1.2.tar.gz.

File metadata

  • Download URL: ehs_llm_client-0.1.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ehs_llm_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b8c1b961cb87072ee84a3a282f78b502810741fb60996841c32c2f39e2a007fd
MD5 2ae632289966599a83aec80f9a69b2ee
BLAKE2b-256 73eb4aeac26a6f3a82f2f30bc9e26aa90c72081e28138e647a7eda1b1b6f6ccb

See more details on using hashes here.

File details

Details for the file ehs_llm_client-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ehs_llm_client-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ehs_llm_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b14fc96735d5ea3bb3ef3c548df218fdf0b094b6df5c5167a665ace4ff829aaa
MD5 e7163e66b886079092b1ad26b78b8f54
BLAKE2b-256 16457faa08e1cb5aa6f6568d2682638d0502578417c9943331419dda9c0c86fd

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