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.7.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.1.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.1.0
File Size Uploaded
llm_catalog_ai_sdk-0.1.0.tar.gz 10.8 kB Details

Built distribution (wheel)

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

Total release size: 23.4 kB

Release files / llm_catalog_ai_sdk-0.1.0.tar.gz

Download URL llm_catalog_ai_sdk-0.1.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
354ff5932bdad3f343e5ecc77d2d17e89136fbf5644582a29b080613e760f4f0
BLAKE2b-256 checksum
How to use checksums
9395106be5fdd892012efcf57ae98ed7ae92b3f9050759c20d15efd387a37c5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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.1.0-py3-none-any.whl

Download URL llm_catalog_ai_sdk-0.1.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48f1f33711d64f316cdb9118b1e723700c1c549df4f88f354000460297d17845
BLAKE2b-256 checksum
How to use checksums
2726c752c04ce930dd0ecd4d4b19a18dacdc9f5cc95a4139a5b26e933297a973
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","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.1.0 This release

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