Skip to main content

llm-catalog-ai-sdk

AI SDK for Python adapter for llm-catalog. It turns a role in your catalog config (ai-sdk-catalog.json, shared verbatim with ai-sdk-catalog) into a native ai.Model — a gateway model is routed through your gateway via the core GatewayTransport, a direct model calls the vendor's own endpoint.

import json
from pathlib import Path

import ai
from llm_catalog.ai_sdk import AISDKCatalog

config = json.loads(Path("ai-sdk-catalog.json").read_text(encoding="utf-8"))

async with AISDKCatalog(config) as cat:  # closes its HTTP clients on exit
    model = cat.model_for_role("fast")
    params = cat.params_for_role("fast")
    async with ai.stream(model, [ai.user_message("hi")], params=params) as stream:
        async for event in stream:
            if isinstance(event, ai.events.TextDelta):
                print(event.chunk, end="", flush=True)

ai.Model carries no default call settings, so the catalog's merged settings come back separately from params_for_role() / params() as an ai.InferenceRequestParams to pass (or refine) per call. providerOptions is skipped: its entries are options of the TypeScript AI SDK providers and have no counterpart here.

Vendors and call surfaces

ai speaks three wire protocols directly, which covers three of the shared schema's vendors. Every other combination raises LLMCatalogError when the model is built; nothing is silently routed to a different API.

Vendor api omitted responses chat completion
anthropic Messages error Messages error
openai Responses Responses Chat Completions error
openai-compatible Chat Completions error Chat Completions error
any other vendor error error error error

chat on anthropic follows ai-sdk-catalog, where a single-surface vendor exposes chat as an alias of its one surface. google, mistral, groq, and the other vendors of the shared schema have no native protocol in ai; declare an endpoint that speaks Chat Completions as an openai-compatible vendor (or backend) instead. stopSequences has no stop parameter on the OpenAI Responses API, so it raises there rather than being dropped.

Beta notice

ai is in public beta and may change its API in any 0.x minor release. This adapter pins the ai minor line it is tested against (currently 0.8.x) and uses only ai's documented surface: ai.get_provider with base_url / api_key / client, ai.Model with an explicit protocol, and ai.InferenceRequestParams. Its tests send requests through ai to a mock transport, so an ai release that stops honouring the injected client fails CI instead of failing at runtime.

Requires Python 3.12+ (the floor of ai). The HTTP client is httpx2, which ai and the official OpenAI / Anthropic SDKs are built on; the header_rewrite / body_rewrite hooks receive httpx2.Headers / httpx2.Request. Pass transport_factory to supply the underlying httpx2 transport yourself (a proxy, mTLS, connection limits, or httpx2.MockTransport in tests). Installing this package pulls in neither pydantic-ai nor litellm.

See the repository README for the full picture and the verification notes (§9).

import namespace: llm_catalog.ai_sdk

Metadata

Release files for llm-catalog-ai-sdk 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-catalog-ai-sdk 0.2.1
File Size Uploaded
llm_catalog_ai_sdk-0.2.1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-catalog-ai-sdk 0.2.1
File Interpreter ABI Platform
llm_catalog_ai_sdk-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / llm_catalog_ai_sdk-0.2.1.tar.gz

Download URL llm_catalog_ai_sdk-0.2.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f67dc7a7afae522cd5a17a43fd608678ee7518f7b3de7ba8d93fb41e5868108f
BLAKE2b-256 checksum
How to use checksums
d9a0d0b75611284ada5642b07cabeef3258225ff981b58ff71d59e08c125dcbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llm_catalog_ai_sdk-0.2.1-py3-none-any.whl

Download URL llm_catalog_ai_sdk-0.2.1-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
182fc1d4666d1137a0d4b7e1fc3943050fe44bf84ccef0b93bc1d0d1cb2f6364
BLAKE2b-256 checksum
How to use checksums
ddb0fb34d1a28c0374ba6a1b0878be48c6d412c51dfb684d0850961feefa00fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page