Unified LLM Interface
Write once, run everywhere

A powerful Python library providing seamless interaction with all major LLM providers with centralized configuration, universal media handling, and vision capabilities. Switch between OpenAI, Anthropic, Ollama, and more with identical code.

🤖 For AI Agents: Use our AI-optimized documentation at llms.txt (concise) or llms-full.txt (complete) for seamless integration.

6+
Providers
137+
Models
MIT
License
example.py
from abstractcore import create_llm

# Works with any provider - just change the name
llm = create_llm("anthropic", model="claude-haiku-4.5")
response = llm.generate("What is the capital of France?")
print(response.content)

# Switch providers with zero code changes
llm = create_llm("openai", model="gpt-4o-mini")
llm = create_llm("ollama", model="qwen3-coder:30b")

# Same interface, same results ✨

Why Choose AbstractCore?

Production-ready LLM infrastructure with everything you need to build reliable AI applications.

Centralized Configuration

One-time setup with ~/.abstractcore/config/abstractcore.json. Set global defaults, app-specific preferences, and API keys. Never specify providers repeatedly again.

Universal Media Handling

Attach any file with simple @filename syntax. Images, PDFs, Office docs, CSV/TSV automatically processed. Same API across all providers with intelligent fallback.

Vision Capabilities

Image analysis across all providers with automatic optimization. Vision fallback for text-only models through smart captioning. Multi-image support with resolution handling.

Provider Discovery

Centralized registry with 137+ models across 6 providers. Programmatically discover all available providers and models with comprehensive metadata.

Production Ready

Built-in retry logic, circuit breakers, comprehensive error handling, and event-driven observability.

Universal Tools + Syntax Rewriting

Tool calling across ALL providers with real-time format conversion for agent CLI compatibility. Architecture-aware detection and custom tag support.

Type Safe

Full Pydantic integration for structured outputs with automatic validation and retry on failures.

Local & Cloud

Run models locally for privacy and cost savings, or use cloud APIs for maximum performance.

Token Management + Streaming

Unified token parameters across all providers with budget validation. Real-time streaming with proper tool call handling and cost estimation.

Session Management + Analytics

Persistent conversations with SOTA 2025 auto-compaction algorithm. Built-in analytics: summaries, assessments, fact extraction with complete serialization.

Production Resilience + OpenAI Server

Production-grade retry logic, circuit breakers, and event-driven monitoring. OpenAI-compatible HTTP server for multi-language access.

Get Started in Minutes

Install AbstractCore and make your first LLM call in under 5 minutes.

1

Install

Install AbstractCore with your preferred providers

# Install everything
pip install abstractcore[all]

# Or install specific providers
pip install abstractcore[openai]
pip install abstractcore[anthropic]
2

Configure

Set up your API keys or local providers

# For cloud providers
export OPENAI_API_KEY="your-key-here"
export ANTHROPIC_API_KEY="your-key-here"

# For local providers (no keys needed)
# Install Ollama, LMStudio, or MLX
3

Code

Start building with the unified interface

from abstractcore import create_llm

# Create LLM instance
llm = create_llm("openai", model="gpt-4o-mini")

# Generate response
response = llm.generate("Hello, world!")
print(response.content)
centralized_configuration.sh
# Check current configuration
abstractcore --status

# Set global fallback model (used when no app-specific default)
abstractcore --set-global-default ollama/llama3:8b

# Set app-specific defaults for optimal performance
abstractcore --set-app-default summarizer openai gpt-4o-mini
abstractcore --set-app-default cli ollama qwen3:4b

# Configure vision fallback for text-only models
abstractcore --download-vision-model  # Download local model
# OR use existing model:
# abstractcore --set-vision-caption qwen2.5vl:7b

# Set API keys
abstractcore --set-api-key openai sk-your-key-here

# Configure logging
abstractcore --set-console-log-level WARNING

# Now use without specifying provider/model every time!
python -m abstractcore.utils.cli --prompt "Hello!"  # Uses configured defaults
media_handling.py
from abstractcore import create_llm

# Works with any provider - same API everywhere
llm = create_llm("openai", model="gpt-4o")

# Attach any file type with media parameter
response = llm.generate(
    "What's in this image and document?",
    media=["photo.jpg", "report.pdf"]
)

# Or use CLI with @filename syntax
# python -m abstractcore.utils.cli --prompt "Analyze @report.pdf"

# Supported file types:
# - Images: PNG, JPEG, GIF, WEBP, BMP, TIFF
# - Documents: PDF, DOCX, XLSX, PPTX
# - Data: CSV, TSV, TXT, MD, JSON

# Same code works with any provider
llm = create_llm("anthropic", model="claude-3.5-sonnet")
response = llm.generate(
    "Summarize these materials",
    media=["chart.png", "data.csv", "presentation.pptx"]
)
vision_capabilities.py
from abstractcore import create_llm

# Vision works across all providers with same interface
openai_llm = create_llm("openai", model="gpt-4o")
response = openai_llm.generate(
    "Describe this image in detail",
    media=["photo.jpg"]
)

# Same code with local provider
ollama_llm = create_llm("ollama", model="qwen2.5vl:7b")
response = ollama_llm.generate(
    "What objects do you see?",
    media=["scene.jpg"]
)

# Vision fallback for text-only models
# Configure once: abstractcore --download-vision-model
text_llm = create_llm("lmstudio", model="qwen/qwen3-next-80b")  # No native vision
response = text_llm.generate(
    "What's in this image?",
    media=["complex_scene.jpg"]
)
# Works transparently: vision model analyzes → text model processes description

# Multi-image analysis
response = llm.generate(
    "Compare these architectural styles",
    media=["building1.jpg", "building2.jpg", "building3.jpg"]
)
tool_syntax_rewriting.py
from abstractcore import create_llm
from abstractcore.tools import tool

@tool
def calculate(expression: str) -> float:
    """Perform mathematical calculation."""
    return eval(expression)

# Custom tag configuration for agent CLI compatibility
llm = create_llm(
    "ollama",
    model="qwen3-coder:30b",
    tool_call_tags="function_call"  # Converts to ...
)

# Real-time streaming with format conversion
for chunk in llm.generate("Calculate 15 * 23", tools=[calculate], stream=True):
    if chunk.tool_calls:
        print(f"Tool detected: {chunk.tool_calls[0].name}")
    print(chunk.content, end="", flush=True)
session_analytics.py
from abstractcore import BasicSession, create_llm

llm = create_llm("openai", model="gpt-4o-mini")
session = BasicSession(llm, system_prompt="You are a helpful assistant.")

response1 = session.generate("My name is Alice")
response2 = session.generate("What's my name?")  # Remembers context

# Auto-compaction with SOTA 2025 algorithm
session.compact(target_tokens=8000)  # Compresses while preserving context

# Advanced analytics
summary = session.generate_summary(style="executive", length="brief")
assessment = session.generate_assessment(criteria=["clarity", "helpfulness"])
facts = session.extract_facts(entity_types=["person", "organization", "date"])

# Save with analytics
session.save("conversation.json", summary=True, assessment=True, facts=True)
token_management.py
from abstractcore import create_llm
from abstractcore.utils.token_utils import estimate_tokens

# Unified token parameters work across ALL providers
llm = create_llm(
    "anthropic",
    model="claude-haiku-4.5",
    max_tokens=32000,           # Context window (input + output)
    max_output_tokens=8000,     # Maximum output tokens
    max_input_tokens=24000      # Maximum input tokens (auto-calculated if not set)
)

# Token estimation and validation
text = "Your input text here..."
estimated = estimate_tokens(text, model="claude-haiku-4.5")
print(f"Estimated tokens: {estimated}")

# Budget validation with warnings
response = llm.generate("Write a detailed analysis...")
print(f"Input tokens: {response.usage.input_tokens}")
print(f"Output tokens: {response.usage.output_tokens}")
print(f"Cost estimate: ${response.usage.cost_usd:.4f}")
http_server.py
# Start OpenAI-compatible server
# uvicorn abstractcore.server.app:app --host 0.0.0.0 --port 8000

import requests

# NEW: OpenAI Responses API with native file support
response = requests.post(
    "http://localhost:8000/v1/responses",
    json={
        "model": "gpt-4o",
        "input": [
            {
                "role": "user",
                "content": [
                    {"type": "input_text", "text": "Analyze this document"},
                    {"type": "input_file", "file_url": "https://example.com/report.pdf"}
                ]
            }
        ],
        "stream": False  # Optional streaming
    }
)

# Or use standard chat completions with @filename syntax
import openai
client = openai.OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
response = client.chat.completions.create(
    model="ollama/qwen3-coder:30b",
    messages=[{"role": "user", "content": "Analyze @report.pdf"}]
)

Supported Providers

One interface for all major LLM providers. Switch between them with a single line change.

Comprehensive Documentation

Everything you need to build production-ready LLM applications. AI agents: Use our optimized llms.txt or llms-full.txt for direct integration.

Real-World Examples

Learn from practical examples and use cases.

Provider Flexibility

Core Feature

Switch between providers with identical code. Perfect for development vs production environments.

# Development (free, local)
llm_dev = create_llm("ollama", model="qwen3:4b")

# Production (high quality, cloud)
llm_prod = create_llm("openai", model="gpt-4o-mini")

# Same interface, different capabilities
View Full Example →

RAG with Embeddings

Advanced

Build retrieval-augmented generation systems with built-in embedding support.

from abstractcore.embeddings import EmbeddingManager

embedder = EmbeddingManager()
docs_embeddings = embedder.embed_batch(documents)

# Find most similar document
query_embedding = embedder.embed("user query")
similarity = embedder.compute_similarity(query, docs[0])
View Full Example →

Universal API Server

Server

Deploy an OpenAI-compatible API server that works with all providers.

# Start server
uvicorn abstractcore.server.app:app --port 8000

# Use with any OpenAI client
curl -X POST http://localhost:8000/v1/chat/completions \
  -d '{"model": "ollama/qwen3-coder:30b", ...}'
View Full Example →

CLI Apps & Debug Mode

New

Ready-to-use terminal tools with debug capabilities and focus areas for targeted processing.

# Extract knowledge with debug mode
extractor document.pdf --format json-ld --debug --iterate 3

# Evaluate with focus areas
judge README.md --focus "examples, completeness" --debug

# Self-healing JSON handles truncated responses automatically
View CLI Docs →