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.0

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.0
File Size Uploaded
llm_catalog_ai_sdk-0.2.0.tar.gz 11.6 kB Details

Built distribution (wheel)

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

Total release size: 24.2 kB

Release files / llm_catalog_ai_sdk-0.2.0.tar.gz

Download URL llm_catalog_ai_sdk-0.2.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
10fbf9e7032b1310eefca506d18ffc32368a23e70c0944a7c4deb33eb79633fb
BLAKE2b-256 checksum
How to use checksums
0ae375ad82c2304d607a2642598916832b417dbdec6049ff7cd9617a04746ffe
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.0-py3-none-any.whl

Download URL llm_catalog_ai_sdk-0.2.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4d3af3a99742a8aacb4efc65e945aee35fbf228d63a20844489981877a431cb
BLAKE2b-256 checksum
How to use checksums
9c311eae8fa1e24ac10a03bd348d060b8a58c13b87737ad81fb64c2904e694a9
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

0.2.1

2 release files

This release

0.2.0 This release

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