Skip to main content

cross-ai-core

PyPI version Python License: MIT

Multi-provider AI dispatcher with MD5-keyed response caching and unified error handling.

Supports Anthropic, xAI (Grok), OpenAI, Google Gemini, Perplexity, and Ollama (local/LAN, keyless) through a single consistent interface.

Requirements

  • Python 3.10 or newer (3.11 recommended for development)
  • No upper version limit — tested on 3.10–3.13

Install

Install only the provider(s) you need:

pip install "cross-ai-core[anthropic]"   # Claude
pip install "cross-ai-core[gemini]"      # Google Gemini
pip install "cross-ai-core[openai]"      # OpenAI (ChatGPT)
pip install "cross-ai-core[xai]"         # xAI Grok  (uses the OpenAI SDK)
pip install cross-ai-core                # Perplexity or Ollama (uses requests, no extra SDK)

Install all providers at once (used by cross-st, which runs multiple providers simultaneously):

pip install "cross-ai-core[all]"

Dependencies

requests is always installed — it is used for the Perplexity and Ollama providers and general HTTP.
The three provider SDKs are optional extras; pip installs only what you request.

Extra Package Version Providers covered
(base) requests ≥2.32.4 Perplexity, Ollama (local/LAN, keyless)
[anthropic] anthropic ≥0.84.0 Anthropic / Claude
[gemini] google-genai ≥1.65.0 Google Gemini
[openai] openai ≥1.70.0 OpenAI
[xai] openai ≥1.70.0 xAI / Grok (OpenAI-compatible API)
[all] all three above — All 6 providers

Quick start

Calls are dispatched through agents — named (provider, model) pairs. See the cross-st Agents wiki page for the full concept; the minimal version is one JSON file at ~/.cross_ai_models.json:

{
  "version": 2,
  "agents": {
    "xai":       {"make": "xai",       "model": null},
    "anthropic": {"make": "anthropic", "model": null}
  }
}

If you also use cross-st, running st-admin --setup once will detect every API key in ~/.crossenv and seed one starter agent per provider for you. Standalone users can write the file by hand or set CROSS_AI_AGENTS_FILE=/path/to/file.json to point at an alternative.

import os
from dotenv import load_dotenv
load_dotenv(os.path.expanduser("~/.crossenv"))  # your app loads keys; the library reads os.environ

from cross_ai_core import process_prompt, get_content_auto, get_default_ai

agent  = get_default_ai()           # DEFAULT_AGENT env var, then DEFAULT_AI (legacy),
                                    # then first agent in ~/.cross_ai_models.json
result = process_prompt(
    agent,
    "Explain transformer attention in 3 sentences.",
    system="You are a concise technical writer.",   # omit to use each provider's default
    verbose=False,
    use_cache=True,
)
print(get_content_auto(result.response))            # auto-dispatches via the _make stamp

Breaking change in 0.8.0: built-in provider names are no longer auto-registered as self-agents. process_prompt("xai", …) raises ValueError: Unsupported AI model: 'xai'. No agents defined. if the registry is empty. Define at least one agent (above) before the first call.

For older callers, get_content(agent, result.response) still works (it alias-resolves the agent → provider make internally).

Configuration (environment variables)

Variable Default Purpose
DEFAULT_AGENT (first agent in registry) Default agent when none is specified (set by st-admin > AI > d in cross-st 0.10+)
DEFAULT_AI — Legacy pre-Agents-v2 spelling of DEFAULT_AGENT; still read for back-compat
CROSS_AI_AGENTS_FILE ~/.cross_ai_models.json Path to the agent registry JSON
<AGENT_UPPER>_MODEL — Per-agent model override (e.g. ANTHROPIC_OPUS_MODEL=claude-opus-future)
<MAKE_UPPER>_MODEL — Per-provider model override (e.g. ANTHROPIC_MODEL=claude-3-5-haiku-latest)
XAI_API_KEY — xAI / Grok API key
ANTHROPIC_API_KEY — Anthropic / Claude API key
OPENAI_API_KEY — OpenAI API key
GEMINI_API_KEY — Google Gemini API key
PERPLEXITY_API_KEY — Perplexity API key
OLLAMA_BASE_URL http://localhost:11434 Ollama daemon location (local or LAN) — keyless
OLLAMA_MODEL llama3.1 Default Ollama model
CROSS_API_CACHE_DIR ~/.cross_api_cache/ Response cache directory
CROSS_NO_CACHE — Set to 1 to disable caching globally
CROSS_NO_CLIENT_CACHE — Set to 1 to disable per-provider client singleton caching

The library only reads from os.environ — it never calls load_dotenv() itself.
Load your .env or ~/.crossenv before importing.
You only need to set API keys for the providers you actually use.

Caching

Responses are cached by MD5 hash of the request payload in ~/.cross_api_cache/.
The cache is safe to delete at any time.

# Bypass cache for one call
result = process_prompt(provider, prompt, verbose=False, use_cache=False)

# Check if a response was served from cache
if result.was_cached:
    print("from cache")

Usage reporting

get_usage_report(provider_or_agent, response) returns a common UsageReport with input/output totals, provider cache and reasoning breakdowns, explicit unknown values, and validation issues. It reads the response without a tokenizer, provider call or extra dependency. See the usage API for the record and examples.

An optional live smoke check sends one small request to a selected provider and checks real response text and usage metadata. It defaults to a dry run; ordinary tests remain offline.

Use AIResponse.was_cached to distinguish local reuse from a new provider request. Cached historical token counts must not be charged again. The older get_usage() dictionary remains available for existing consumers.

Development

cd ~/github/cross-ai-core
python3.11 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"     # installs the package + pytest + pytest-mock

Run the test suite:

python -m pytest tests/ -v

Tests use mocks — no real API keys required.

Note: Keep each repo's .venv separate; do not share it with dependent projects.

Adding a provider

  1. Create cross_ai_core/ai_<name>.py implementing BaseAIHandler (get_payload, get_client, get_cached_response, get_model, get_make, get_content, put_content, get_data_content, get_title, get_usage).
  2. Register in cross_ai_core/ai_handler.py: add to AI_HANDLER_REGISTRY and AI_LIST.

Documentation

Used by

Project PyPI Description
cross-st cross-st Multi-AI research reports with cross-product fact-checking. Installs this package automatically via cross-ai-core[all]. Full CLI toolkit — pipx install cross-st.

Building something with cross-ai-core? Open a PR or issue to get listed here.

Community & support

Questions, ideas, bug reports, or just want to share what you're building?

  • 💬 crossai.dev community forum — Discourse-powered discussion for cross-ai-core, cross-st, and the wider Cross family. Ask questions, share prompts, or compare provider results. Invite-only sign-up keeps it friction-free for real users; see the cross-st wiki for the one-command onboarding (st-admin --discourse-setup).
  • 🐛 GitHub issues — bug reports and feature requests.
  • 🎬 YouTube @crossaicore — walkthroughs and release notes.

Tagline: AI reports. Cross-examined.

License

MIT — free for personal, academic, and open-source use.
See COMMERCIAL_LICENSE.md for organizational and commercial use.

Metadata

Release files for cross-ai-core 2026.11.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 cross-ai-core 2026.11.0
File Size Uploaded Provenance Actions
cross_ai_core-2026.11.0.tar.gz 79.9 kB Without provenance Details for cross_ai_core-2026.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cross-ai-core 2026.11.0
File Interpreter ABI Platform Actions
cross_ai_core-2026.11.0-py3-none-any.whl Python 3 none any Details for cross_ai_core-2026.11.0-py3-none-any.whl

Total release size: 130.3 kB

Release files / cross_ai_core-2026.11.0.tar.gz

Download URL cross_ai_core-2026.11.0.tar.gz
Size 79.9 kB
Tags Source
SHA-256 checksum
How to use checksums
61bedc3e8c874cd51efc4f418b499f6ce38a4bae287bd4c8a5f8a5670a560db4
BLAKE2b-256 checksum
How to use checksums
705b428c4c8964c914247d67a6ce5ba943b6669eefaf2100af9c3af1e6d6ecd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / cross_ai_core-2026.11.0-py3-none-any.whl

Download URL cross_ai_core-2026.11.0-py3-none-any.whl
Size 50.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fc6105f5658e3b1d45754a68e8db70eedec7fa2083ad4325e4cee88dc36ef13
BLAKE2b-256 checksum
How to use checksums
478d04f6938575110c84f091b7220761caa68f79382212c1709f3b32a45d7556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Security for cross-ai-core 2026.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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