Skip to main content

Lightweight wrapper around different LLM provider Python SDK Responses APIs.

Project description

llmconnector

llmconnector is a thin Python wrapper around leading large-language-model SDKs, including the OpenAI Responses API, Google's Gemini SDK, and Anthropic's Claude Messages API. It exposes a minimal interface that forwards the most common options such as API key, prompt, optional reasoning effort hints, token limits, and image inputs, and it includes helpers to enumerate the models available to your account with each provider.

Installation

pip install .

Requirements

  • openai (installed automatically with the package)
  • google-genai (installed automatically with the package)
  • anthropic (installed automatically with the package)

Components

  • OpenAIResponsesClient - direct wrapper around the OpenAI Responses API, ideal when your project only targets OpenAI models. Includes a model discovery helper.
  • GeminiClient - thin wrapper around the Google Gemini SDK, usable when google-genai is installed. Includes a model discovery helper.
  • AnthropicClient - lightweight wrapper around the Anthropic Claude Messages API, usable when anthropic is installed. Includes a model discovery helper.
  • GrokClient - wrapper around the xAI Grok chat API, usable when xai-sdk is installed. Includes a model discovery helper.
  • LLMClient - provider router that delegates to registered clients (OpenAI included by default) so additional vendors can be added without changing call sites.

GeminiClient

Usage

Use the GeminiClient when you want direct access to the Google Gemini SDK without going through the provider router.

Requires the google-genai Python package (installed automatically with llmconnector).

from llmconnector import GeminiClient

client = GeminiClient()

text_response = client.generate_response(
    api_key="your-gemini-api-key",
    prompt="Summarize the key benefits of unit testing.",
    model="gemini-2.5-flash",
    max_tokens=2000,
)

vision_response = client.generate_response(
    api_key="your-gemini-api-key",
    prompt="Describe the main action in this image.",
    model="gemini-2.5-flash",
    images=[
        "/absolute/path/to/local-image.png",
        "https://example.com/sample.jpg",
    ],
)

Parameters

Parameter Type Required Description
api_key str Yes GEMINI or GOOGLE API key used for authentication.
prompt Optional[str] Conditional Plain-text prompt. Required unless images is supplied.
model str Yes Target model identifier, e.g. gemini-2.5-flash.
max_tokens int No Defaults to 32000. Passed to the SDK as max_output_tokens.
reasoning_effort Optional[str] No Present for parity with the OpenAI client; currently ignored by the Gemini SDK.
images Optional[Sequence[str | Path]] No Image references (local paths, URLs, or data URLs) read and forwarded to the Gemini SDK.

The method returns the generated model output as a plain string. Optional image references are automatically converted into the appropriate types.Part instances, allowing you to mix text and visuals in a single request.

Listing models

Use list_models to enumerate the Gemini models available to your account:

from llmconnector import GeminiClient

client = GeminiClient()
for model in client.list_models(api_key="your-gemini-api-key"):
    print(model["id"], model["display_name"])

AnthropicClient

Usage

Use the AnthropicClient when you want direct access to Anthropic's Claude Messages API.

Requires the anthropic Python package (installed automatically with llmconnector).

from llmconnector import AnthropicClient

client = AnthropicClient()

text_response = client.generate_response(
    api_key="sk-ant-api-key",
    prompt="Summarize the key benefits of unit testing.",
    model="claude-sonnet-4-5-20250929",
    max_tokens=2000,
)

vision_response = client.generate_response(
    api_key="sk-ant-api-key",
    prompt="Describe the main action in this image.",
    model="claude-3-5-sonnet-20241022",
    images=[
        "/absolute/path/to/local-image.png",
        "https://example.com/sample.jpg",
    ],
)

Parameters

Parameter Type Required Description
api_key str Yes Anthropic API key used for authentication.
prompt Optional[str] Conditional Plain-text prompt. Required unless images is supplied.
model str Yes Target model identifier, e.g. claude-3-5-sonnet-20241022.
max_tokens int No Defaults to 32000. Passed to the SDK as max_tokens.
reasoning_effort Optional[str] No Present for parity with other clients; currently ignored by the Anthropic SDK.
images Optional[Sequence[str | Path]] No Image references (local paths, URLs, or data URLs) read and converted to base64 blocks.

The method returns the generated model output as a plain string. Optional image references are automatically transformed into Anthropic image blocks so you can mix text and visual inputs in a single request.

Listing models

Use list_models to enumerate the Anthropic models available to your account:

from llmconnector import AnthropicClient

client = AnthropicClient()
for model in client.list_models(api_key="sk-ant-api-key"):
    print(model["id"], model["display_name"])

GrokClient

Usage

Use the GrokClient when you want direct access to xAI's Grok chat API.

Requires the xai-sdk Python package (install manually with pip install xai-sdk). The SDK targets Python 3.10 and newer.

from llmconnector import GrokClient

client = GrokClient()

text_response = client.generate_response(
    api_key="xai-api-key",
    prompt="Summarize the key benefits of unit testing.",
    model="grok-3",
    max_tokens=2000,
)

vision_response = client.generate_response(
    api_key="xai-api-key",
    prompt="Describe the main action in this image.",
    model="grok-2-vision",
    images=[
        "/absolute/path/to/local-image.png",
        "https://example.com/sample.jpg",
    ],
)

Parameters

Parameter Type Required Description
api_key str Yes xAI API key used for authentication.
prompt Optional[str] Conditional Plain-text prompt. Required unless images is supplied.
model str Yes Target model identifier, e.g. grok-3.
max_tokens int No Defaults to 32000. Passed to the Grok API as max_tokens.
reasoning_effort Optional[str] No Hint for reasoning-focused models ("low" or "high").
images Optional[Sequence[str | Path]] No Image references (local paths converted to data URLs, or remote URLs passed through).

Listing models

Use list_models to enumerate the Grok language models available to your account:

from llmconnector import GrokClient

client = GrokClient()
for model in client.list_models(api_key="xai-api-key"):
    print(model["id"], model["display_name"])

OpenAIResponsesClient

Usage

Use the OpenAIResponsesClient when you want direct access to the OpenAI Responses API.

Requires the openai Python package. It is declared as a dependency of llmconnector, but you can also install it manually with pip install openai.

from llmconnector import OpenAIResponsesClient

client = OpenAIResponsesClient()

text_response = client.generate_response(
    api_key="sk-your-api-key",                 # required OpenAI API key
    prompt="Summarize the key benefits of unit testing.",  # plain-text prompt
    model="gpt-4o",                            # any Responses API compatible model
    reasoning_effort="medium",                 # optional: "low" | "medium" | "high"
    max_tokens=2000,                           # optional: caps the full response length
)

vision_response = client.generate_response(
    api_key="sk-your-api-key",
    prompt="Describe the main action in this image.",
    model="gpt-4o-mini",
    images=[
        "/absolute/path/to/local-image.png",   # local file paths are converted to data URLs
        "https://example.com/sample.jpg",      # remote URLs are passed through directly
    ],
)

Parameters

Parameter Type Required Description
api_key str Yes OpenAI API key used for authentication.
prompt Optional[str] Conditional Plain-text prompt. Required unless images is supplied.
model str Yes Target model identifier, e.g. gpt-4o.
max_tokens int No Defaults to 32000. Passed to the Responses API as max_output_tokens.
reasoning_effort Optional[str] No For models that support reasoning hints ("low", "medium", "high").
images Optional[Sequence[str | Path]] No List of image URLs or local paths converted to data URLs.

The method returns the generated model output as a plain string.

The wrapper accepts prompt as plain text and translates it into the structured input format expected by the Responses API.

Listing models

Use list_models to enumerate the OpenAI models available to your account:

from llmconnector import OpenAIResponsesClient

client = OpenAIResponsesClient()
for model in client.list_models(api_key="sk-your-api-key"):
    print(model["id"], model["display_name"])

LLMClient

Usage

LLMClient routes requests to whichever provider has been registered; OpenAI, Gemini, and Anthropic are configured by default when their dependencies are available. The client also exposes list_models to surface the identifiers available for the selected provider.

from llmconnector import LLMClient

llm_client = LLMClient()

response_via_router = llm_client.generate_response(
    provider="openai",                         # selects the OpenAI wrapper
    api_key="sk-your-api-key",
    prompt="List three advantages of integration testing.",
    model="gpt-4o",
    max_tokens=1500,
)

gemini_response = llm_client.generate_response(
    provider="gemini",                         # google-genai is installed with llmconnector
    api_key="your-gemini-api-key",
    prompt="Outline best practices for prompt engineering.",
    model="gemini-2.5-flash",
    max_tokens=1500,
)

anthropic_response = llm_client.generate_response(
    provider="anthropic",
    api_key="sk-ant-api-key",
    prompt="Summarize when to rely on retrieval-augmented generation.",
    model="claude-sonnet-4-5-20250929",
    max_tokens=1500,
)

# Additional providers can be registered at runtime:
# llm_client.register_provider("custom", CustomProviderClient())
# llm_client.generate_response(provider="custom", ...)

Listing models

from llmconnector import LLMClient

llm_client = LLMClient()
for model in llm_client.list_models(provider="openai", api_key="sk-your-api-key"):
    print(model["id"], model["display_name"])

Parameters

Parameter Type Required Description
provider str Yes Registered provider key (default registry includes 'openai', 'gemini', and 'anthropic').
api_key str Yes Provider-specific API key.
prompt Optional[str] Conditional Plain-text prompt. Required unless images is supplied.
model str Yes Provider-specific model identifier.
max_tokens int No Defaults to 32000.
reasoning_effort Optional[str] No Reasoning hint forwarded when supported.
images Optional[Sequence[str | Path]] No Image references forwarded to the provider implementation.

Use LLMClient.register_provider(name, client) to add additional providers that implement generate_response with the same signature.

Development

The project uses a standard pyproject.toml based packaging layout with sources stored under src/. Install the project in editable mode and run your preferred tooling:

pip install -e .

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

ccs_llmconnector-1.0.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

ccs_llmconnector-1.0.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file ccs_llmconnector-1.0.0.tar.gz.

File metadata

  • Download URL: ccs_llmconnector-1.0.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for ccs_llmconnector-1.0.0.tar.gz
Algorithm Hash digest
SHA256 977e1665b801f4f93f9faf1167e3302f2344054bfc2dc2cf70f1d53bb82bd162
MD5 805dcb63f67fe8408fb45a50498f3656
BLAKE2b-256 a34dbe8c14892df2564581313ae389475c17f1f24bbbd15539556f3ef778b28f

See more details on using hashes here.

File details

Details for the file ccs_llmconnector-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ccs_llmconnector-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c3e61125d20bfbe29f3397bbb2e0c5c8a9e9ea89fa45f931c654dd877d456eb
MD5 29342f9256449ac6167b61eb3aac4751
BLAKE2b-256 47fd0d96fc80b6e0873f6c9c7bc5db6865eeb2b3d77198efc21a17e618321138

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