Skip to main content

Unified AI model provider selection and configuration library

Project description

AI Model Picker

A unified Python library for AI model provider selection and configuration. Provides a shared foundation for applications that need to:

  • Select AI providers (OpenAI, Anthropic, Google, Mistral, etc.)
  • Choose models from those providers
  • Manage API keys with environment variable fallback
  • Persist configuration across sessions

Installation

pip install ai-model-picker

Or install from source:

pip install -e /path/to/ai_model_picker

Quick Start

from ai_model_picker import (
    setup_wizard,
    select_provider_and_model,
    get_api_key_with_fallback,
    get_model_api_id,
)

# Run interactive setup
config = setup_wizard(app_name="my-app")

# Or select provider/model programmatically
provider, model = select_provider_and_model()

# Get API key (checks config, then env var)
api_key = get_api_key_with_fallback(provider, app_name="my-app")

# Convert display name to API ID
model_id = get_model_api_id(model, provider)

Features

Supported Providers

  • OpenAI - GPT-4o, GPT-5.x, o3
  • Anthropic - Claude 3.x, 4.x
  • Google - Gemini 2.x, 3.x
  • Mistral - Mistral Large, Devstral
  • Cohere - Command R/R+
  • Meta - Llama 4
  • DeepSeek - R1, V3.x
  • xAI - Grok 4.x
  • Alibaba - Qwen3

Configuration

Configuration is stored in platform-appropriate locations:

  • Linux: ~/.config/{app_name}/config.json
  • macOS: ~/Library/Application Support/{app_name}/config.json
  • Windows: %APPDATA%/{app_name}/config.json

API Key Management

from ai_model_picker import (
    set_api_key,
    get_api_key,
    get_api_key_with_fallback,
    get_all_api_keys,
)

# Store a key
set_api_key("openai", "sk-...", app_name="my-app")

# Get key from config only
key = get_api_key("openai", app_name="my-app")

# Get key with env var fallback (checks OPENAI_API_KEY)
key = get_api_key_with_fallback("openai", app_name="my-app")

# Get all stored keys
keys = get_all_api_keys(app_name="my-app")

Interactive Selection

from ai_model_picker import select_provider, select_model

# Select provider interactively
provider = select_provider()

# Select model for that provider
model = select_model(provider)

Model ID Mapping

Display names are mapped to API IDs automatically:

from ai_model_picker import get_model_api_id

# "Claude 4.5 Sonnet" -> "claude-sonnet-4-5-20250514"
api_id = get_model_api_id("Claude 4.5 Sonnet", "anthropic")

AI Client

Make AI API calls with a unified interface:

from ai_model_picker import call_ai, call_ai_simple, AIResponse

# Simple usage - returns just the text
response = call_ai_simple(
    prompt="Write a hello world function in Python",
    provider="openai",
    model="GPT-4o mini",
    app_name="my-app",
)

# Full response with metadata
result: AIResponse = call_ai(
    prompt="Explain recursion",
    provider="anthropic",
    model="Claude 4.5 Sonnet",
    system_prompt="You are a helpful programming tutor.",
    temperature=0.3,
    max_tokens=1000,
)
print(result.content)
print(result.usage)  # Token usage stats

Provider-Specific Quirks Handled

The unified client handles provider differences internally:

Provider Quirk How It's Handled
Google Returns content as list of parts Automatically joined into string
Cohere Doesn't support timeout parameter Timeout omitted
Anthropic System prompt is separate parameter Handled transparently
DeepSeek, xAI, Meta OpenAI-compatible APIs Correct base URLs configured
Alibaba DashScope API differences Response structure normalized

Check Provider Availability

from ai_model_picker import check_provider_available

available, error = check_provider_available("anthropic")
if not available:
    print(f"Anthropic not available: {error}")

Integration

For applications using this library, specify a custom app_name to isolate configuration:

from ai_model_picker import setup_wizard, load_config

# Each app has its own config file
config = setup_wizard(app_name="ai-auto-commit")
config = load_config(app_name="ai-rules-generator")

Optional Dependencies

Install provider SDKs as needed:

# Core providers
pip install openai anthropic

# Additional providers
pip install google-generativeai  # Google Gemini
pip install mistralai            # Mistral
pip install cohere               # Cohere
pip install dashscope            # Alibaba Qwen

# DeepSeek, xAI, Meta use OpenAI-compatible APIs (just need openai package)

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

ai_model_picker-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

ai_model_picker-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file ai_model_picker-0.1.0.tar.gz.

File metadata

  • Download URL: ai_model_picker-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for ai_model_picker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63c21c64516758b50a52b8df8ffa104c730ec0db503dc5e867e8743513ac47ec
MD5 fbfd90eeda589b84ee572d6833a873f9
BLAKE2b-256 a24adae84564819794b204b0c69619411372e15440326ac2a9d11d6b2b880033

See more details on using hashes here.

File details

Details for the file ai_model_picker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_model_picker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f06f59e1df14c53b5b0b58e8df980e308dd2d61014f0dd205ffc6be1576cffc
MD5 2a2dbbd90e00a566cc17c2e11430969a
BLAKE2b-256 de30f23925a0f026e7f86d7771f2725b89412241597fffc0047f1d21958cbb0a

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