Skip to main content

Unified SDK for AI services with OpenAI compatibility

Project description

SDKRouter

Unified Python SDK for AI services. Access 300+ LLM models, vision, audio, image generation, search, translation, and more through a single interface.

Installation

pip install sdkrouter

Quick Start

from sdkrouter import SDKRouter, Model

client = SDKRouter(api_key="your-api-key")

response = client.chat.completions.create(
    model=Model.cheap(),
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Features

Feature Description Docs
Chat OpenAI-compatible completions, streaming @docs/01-chat.md
Structured Output Pydantic models, JSON extraction @docs/02-structured-output.md
Audio TTS, STT, Deepgram streaming @docs/03-audio.md
Vision Image analysis, OCR @docs/04-vision.md
Image Gen AI image generation @docs/05-image-gen.md
Search Web search with modes @docs/06-search.md
CDN File storage @docs/07-cdn.md
Translator JSON/text translation @docs/08-translator.md
Payments Crypto payments @docs/09-payments.md
Proxies Proxy management @docs/10-proxies.md
Embeddings Text embeddings @docs/11-embeddings.md
Other Shortlinks, cleaner, models API @docs/12-other.md

Model Routing

Smart model selection with IDE autocomplete:

from sdkrouter import Model

Model.cheap()                    # Lowest cost
Model.smart()                    # Highest quality
Model.balanced()                 # Best value
Model.fast()                     # Fastest

# With capabilities
Model.cheap(vision=True)         # + vision
Model.smart(tools=True)          # + function calling
Model.balanced(json=True)        # + JSON mode

# Categories
Model.smart(code=True)           # Coding
Model.cheap(reasoning=True)      # Problem solving

Async Support

from sdkrouter import AsyncSDKRouter, Model
import asyncio

async def main():
    client = AsyncSDKRouter(api_key="your-api-key")

    response = await client.chat.completions.create(
        model=Model.cheap(),
        messages=[{"role": "user", "content": "Hello!"}]
    )

    # Parallel requests
    results = await asyncio.gather(
        client.vision.analyze(image_url="..."),
        client.audio.speech(input="Hello!"),
    )

asyncio.run(main())

Audio Example

from sdkrouter import SDKRouter, AudioModel

client = SDKRouter()

# Text-to-Speech
response = client.audio.speech(
    input="Hello!",
    model=AudioModel.cheap(),
    voice="nova",
)
Path("output.mp3").write_bytes(response.audio_bytes)

# Speech-to-Text
result = client.audio.transcribe(file=audio_bytes)
print(result.text)

Deepgram Streaming

from sdkrouter import AsyncSDKRouter
from sdkrouter.tools.audio.stt import DeepgramConfig

sdk = AsyncSDKRouter()

config = DeepgramConfig(
    model="nova-3",
    endpointing=300,   # VAD: silence threshold (ms)
    vad_events=True,   # Enable VAD events
)

async with sdk.audio.stt.stream_deepgram(config) as session:
    await session.send(audio_chunk)
    async for segment in session.transcripts():
        print(segment.text)

Configuration

# Environment variables (auto-loaded)
# SDKROUTER_API_KEY
# SDKROUTER_LLM_URL
# SDKROUTER_API_URL
# SDKROUTER_AUDIO_URL

client = SDKRouter(
    api_key="your-key",
    timeout=60.0,
    max_retries=3,
)

Prompt Caching & Metrics

For Anthropic Claude models, SDKRouter automatically applies cache_control breakpoints. Cache metrics are returned in response.usage.prompt_tokens_details:

response = client.chat.completions.create(
    model="anthropic/claude-haiku-4-5",
    messages=[...],  # long conversation
)

details = response.usage.prompt_tokens_details
if details:
    print("Cache read tokens: ", details.cached_tokens)      # billed at 10%
    print("Cache write tokens:", details.cache_write_tokens) # billed at 125%

No client-side changes needed — caching is transparent and automatic.

Supported Providers

  • OpenAI: GPT-4.5, GPT-4o, o3, o1
  • Anthropic: Claude Opus 4.5, Claude Sonnet 4
  • Google: Gemini 2.5 Pro, Gemini 2.0 Flash
  • Meta: Llama 4, Llama 3.3
  • Mistral: Mistral Large, Codestral
  • DeepSeek: DeepSeek V3, R1
  • And 300+ more via OpenRouter

License

MIT

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

sdkrouter-0.1.27.tar.gz (166.7 kB view details)

Uploaded Source

Built Distribution

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

sdkrouter-0.1.27-py3-none-any.whl (253.2 kB view details)

Uploaded Python 3

File details

Details for the file sdkrouter-0.1.27.tar.gz.

File metadata

  • Download URL: sdkrouter-0.1.27.tar.gz
  • Upload date:
  • Size: 166.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for sdkrouter-0.1.27.tar.gz
Algorithm Hash digest
SHA256 1bdfa8cde0b69cee572cbe3d1de19135d29dfffd8f640fc17fa1e44a22baff29
MD5 f4c7ccebad732fd9ba0eb9ee9a406eec
BLAKE2b-256 c9f96dd65ad090c62d3172994cb400d222ff0c225cb4ec49fc20ac5d8b286f5f

See more details on using hashes here.

File details

Details for the file sdkrouter-0.1.27-py3-none-any.whl.

File metadata

  • Download URL: sdkrouter-0.1.27-py3-none-any.whl
  • Upload date:
  • Size: 253.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for sdkrouter-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 ab54fcb21866bb51de31fda3cc22f81d5b63cc757008dbfe52a3491432b43fae
MD5 ab6c6a98add55c401e01882a3069e32e
BLAKE2b-256 5f9d04f8122148adb35fd53459f536aa9eaad797b4e9cfa90e682c89ebc88650

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