Skip to main content

aichain

The simplest way to build AI pipelines. 11 cloud providers + your own private server. 1 interface. Zero lock-in.

from yait_aichain import Model, Skill

skill = Skill(
    model  = Model("claude-sonnet-4-6"),   # change this one word to switch providers
    input  = {"messages": [{"role": "user", "parts": ["Summarise: {text}"]}]},
)

result = skill.run(variables={"text": "..."})

Change "claude-sonnet-4-6" to "gpt-4o", "gemini-2.5-pro", or "grok-3" — nothing else changes.


Why aichain?

Every major AI library makes you choose: LangChain is too complex, LlamaIndex is RAG-only, CrewAI is agents-only, AutoGen requires a PhD to configure.

aichain covers the full stack with the simplest interface:

Need aichain primitive
Call any LLM Skill
Chain steps together Chain
Run tasks in parallel Pool
Autonomous reasoning Agent
Vector search + RAG VectorDB + vectorQuery
Rerank results Reranker
Call any tool or MCP server Tool / MCPTools

All of these work identically across 90 models from 11 cloud providers — plus any open-weight model you host yourself, where the data never leaves your perimeter — with one line to swap any of them.


Install

pip install yait-aichain

Optional extras:

pip install markitdown   # file/URL → Markdown
pip install pyyaml       # save & load Skills and Chains
pip install fastmcp      # MCP server integration

API keys — only for the providers you use:

export ANTHROPIC_API_KEY="…"
export BFL_API_KEY="…"
export DEEPSEEK_API_KEY="…"
export GOOGLE_AI_API_KEY="…"
export MOONSHOT_API_KEY="…"
export OPENAI_API_KEY="…"
export PERPLEXITY_API_KEY="…"
export DASHSCOPE_API_KEY="…"
export RECRAFT_API_TOKEN="…"
export REVE_API_KEY="…"
export XAI_API_KEY="…"
export BRAVE_SEARCH_API_KEY="…"
export COHERE_API_KEY="…"
export GOOGLE_API_KEY="…"
export SERPAPI_API_KEY="…"
export VOYAGE_API_KEY="…"

Every provider, one syntax

from yait_aichain.models import Model

Model("claude-sonnet-4-6")   # Anthropic
Model("gpt-4o")              # OpenAI
Model("gemini-2.5-flash")    # Google
Model("grok-3")              # xAI
Model("sonar-pro")           # Perplexity
Model("kimi-k2.5")           # Kimi
Model("deepseek-chat")       # DeepSeek
Model("qwen-max")            # Qwen
Model("private/llama3.3")    # your own server — vLLM, Ollama, LM Studio, …

88 cloud models total (full list: model registry →). The private provider needs no key and accepts whatever your server serves — the prompts and the answers stay inside your perimeter (private models →).


Core concepts

Skill — one prompt, any model

skill  = Skill(model=Model("gpt-4o-mini"), input={...})
result = skill.run(variables={"topic": "neural networks"})

Chain — sequential steps, automatic variable flow

chain = Chain(steps=[
    (fetch_tool,    "page"),
    (summarise,     "summary"),
    (translate,     "result"),
])
result = chain.run(variables={"url": "https://…", "language": "French"})
print(chain.history)   # full audit trail

Pool — parallel execution

pool    = Pool(summarise_skill, items=[{"text": t} for t in documents], max_flows=10)
results = pool.run()                    # all documents processed simultaneously

print(pool.status)   # {PENDING: 0, RUNNING: 0, DONE: 50, FAILED: 0}
print(pool.history)  # per-item: status, output, error, duration

Agent — autonomous reasoning

from yait_aichain.agent import Agent, step_count

agent  = Agent(
    model        = Model("claude-opus-4-8"),
    tools        = [searchPerplexity(), convertToMD()],
    mode         = "agile",
    stop_when    = [step_count(10)],
)
result = agent.run("Compare the top 3 vector databases.")
print(result.output)
print(f"steps={result.steps_taken}  tokens={result.tokens_used:,}")

Full RAG pipeline

from yait_aichain.tools.embedding import Embedding
from yait_aichain.tools.vectordb  import VectorDB, vectorChunk, vectorUpsert, vectorQuery
from yait_aichain.tools.reranking import Reranker

store    = VectorDB("chroma", "docs", embedder=Embedding("cohere/embed-v4.0"))
reranker = Reranker("cohere/rerank-v3.5")

# Ingest
chunks = vectorChunk(max_chars=800).run(my_document)
vectorUpsert(store).run([{"id": f"c{i}", **c} for i, c in enumerate(chunks)])

# Query → rerank → answer
pipeline = Chain(steps=[
    (vectorQuery(store),  "candidates", {"input": "{question}", "options": {"n": 20}}),
    (reranker,            "context",    {"input": "{candidates}",
                                         "options": {"query": "{question}", "top_n": 5}}),
    answer_skill,
])
answer = pipeline.run(variables={"question": "How does KV caching work?"})

Vector DB providers: Chroma · Qdrant · Pinecone Reranking providers: Cohere · Voyage · Qwen


Cost, routing & resilience

These are all opt-in — the minimal program above is unchanged.

Token usage & cost — every result carries normalised usage:

skill.run()
skill.last_usage.input_tokens   # 1240
skill.last_usage.total_tokens   # 1310
skill.last_usage.cost           # 0.0032  (USD, None if the model has no price)

chain.run()
chain.last_usage.cost           # summed across all Skill steps

Explicit provider routing — pick the provider with a provider/model prefix; it also unlocks custom / fine-tuned names the auto-detector can't recognise:

Model("openai/gpt-4o")                 # same as Model("gpt-4o")
Model("openai/ft:gpt-4o:acme:42")      # custom name, explicit provider

Fallback chain — pass a list; a transient failure (rate limit / server / network) advances to the next model. A real error (bad key, bad request) still raises immediately:

skill = Skill(
    model = [Model("claude-sonnet-4-6"), Model("gpt-4o")],  # primary, then backup
    input = {"messages": [{"role": "user", "parts": ["..."]}]},
)

Typed errors — catch a specific failure mode, or APIError for all:

from yait_aichain import (RateLimitError, AuthenticationError,
                          InsufficientCreditsError, APIError)

try:
    skill.run()
except RateLimitError as e:
    wait(e.retry_after)        # honours the Retry-After header
except InsufficientCreditsError:
    ...                        # out of credits/quota — top up (not a key problem)
except AuthenticationError:
    ...

Keep the model list fresh — diff the registry against a provider's live roster:

from yait_aichain.models import registry
registry.refresh("openai")     # → {"new": [...], "removed": [...], ...}

Built-in tools

Search

searchPerplexity · searchBrave · searchSerp · searchOpenAI

Convert

convertToMD · convertToHTML · convertToPDF · TTS(provider) · STT(provider)

Embeddings

Embedding("openai/text-embedding-3-small")
Embedding("cohere/embed-v4.0")
Embedding("voyage/voyage-3-large")

Examples

→ examples/ — one concept per file

# File What it shows
01 01_skill.py Run a prompt against a model.
02 02_skill_models.py Same prompt, three providers.
03 03_skill_multimodal.py Text → Image → Text, three different providers.
04 04_skill_save_load.py Save a skill to YAML, reload and run it.
05 05_tool_convert.py Convert a URL or file to Markdown.
06 06_tool_mcp.py Connect to an MCP server, discover tools, run them.
07 07_tool_custom.py Define your own tool and use it in a Chain.
08 08_chain.py Two skills in sequence, two different providers.
09 09_chain_tool_skill.py Tool + Skill in one chain.
10 10_chain_save_load.py Save a chain to YAML, reload and run it.
11 11_pool.py Run the same skill in parallel for multiple inputs.
12 12_pool_chain.py Chain as a Pool runner.
13 13_agent.py Basic agent with one tool.
14 14_agent_tools.py Agent with multiple tools, picks autonomously.
15 15_agent_orchestrator.py Orchestrator agent spawns sub-agents.
16 16_debug.py Inspect intermediate steps in Chain, Pool, and Agent.
17 17_chain_human_input.py Human-in-the-loop: pause a chain for manual input.
18 18_chain_external_trigger.py Pause a run until an EXTERNAL trigger resumes it.
19 19_image_edit.py Image → image (editing) across four providers, one Skill.
20 20_observability.py The step boundary: hooks, events, and an approval gate.
21 21_multi_turn.py Directed multi-turn reasoning in ONE Skill.
22 22_goal_mode.py A stop condition the harness can verify
23 23_private_model.py Run a model on hardware you control.
24 24_scaffold.py Scaffold — the model designs the team, then runs it

Persist and reload

skill.save("skills/translator.yaml")
skill = Skill.load("skills/translator.yaml")   # API key from env, not file

chain.save("chains/research.yaml")
chain = Chain.load("chains/research.yaml")

Supported providers

Provider Text Vision Image gen Env var
Anthropic Claude Fable 5, Opus / Sonnet / Haiku 4 ✓ — ANTHROPIC_API_KEY
OpenAI GPT-5.5, GPT-5.4, GPT-4o ✓ ChatGPT-Image, GPT-Image-2 OPENAI_API_KEY
Google Gemini 2.5 Pro / Flash, 3.x ✓ Gemini image models GOOGLE_AI_API_KEY
xAI Grok 4, Grok 3 ✓ Grok-Imagine XAI_API_KEY
Perplexity Sonar Pro, Sonar, Deep Research — — PERPLEXITY_API_KEY
Kimi K2.7 Code, K2.6, K2.5, K2 Thinking ✓ — MOONSHOT_API_KEY
DeepSeek DeepSeek-V3, DeepSeek-R1 — — DEEPSEEK_API_KEY
Qwen Qwen-Max, Qwen3, QwQ ✓ Wan 2.2 image DASHSCOPE_API_KEY
Recraft — — Recraft V3 (raster + vector) RECRAFT_API_TOKEN
BFL (FLUX) — — FLUX.2, FLUX Kontext BFL_API_KEY
Reve — — Reve Image (create / edit / remix) REVE_API_KEY

Image editing — instruction edit, preserves the subject: OpenAI · Google · xAI · Qwen · FLUX Kontext (place / restyle / recompose while keeping the original object)
Image-to-image — whole-image variation (restyle, not subject-preserving): Recraft (imageToImage, strength-controlled)
Embedding: OpenAI · Cohere · Voyage · Google · Qwen
Reranking: Cohere · Voyage · Qwen
Vector DB: Chroma · Qdrant · Pinecone


License

MIT


Changelog

Every release is in CHANGELOG.md — what changed, and why it changed. Releases before 2.0 are recorded incompletely; the file says which ones and why they were not reconstructed.

Metadata

Release files for yait-aichain 2.18.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yait-aichain 2.18.1
File Size Uploaded
yait_aichain-2.18.1.tar.gz 368.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yait-aichain 2.18.1
File Interpreter ABI Platform
yait_aichain-2.18.1-py3-none-any.whl Python 3 none any Details

Total release size: 737.6 kB

Release files / yait_aichain-2.18.1.tar.gz

Download URL yait_aichain-2.18.1.tar.gz
Size 368.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fb5036e8354086a6cfe38128fd4f7b422c68a5bdcc968cda5987bcdf93c47c1f
BLAKE2b-256 checksum
How to use checksums
cbdad63025d269bc4452fe424c897595932f5ec7ffb296901bf5809beb81525a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / yait_aichain-2.18.1-py3-none-any.whl

Download URL yait_aichain-2.18.1-py3-none-any.whl
Size 369.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3caf15a07ed08cb13265c5f0fa9ff437587de6aced56ffde863268717628744d
BLAKE2b-256 checksum
How to use checksums
8787ae13cba50ea7706808acf5f2e5a648120f0de878318c3909b2e1b58a2003
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release history Release notifications | RSS feed

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.19.0

2 release files

This release

2.18.1 This release

2 release files

2.18.0

2 release files

2.17.1

2 release files

2.17.0

2 release files

2.16.0

2 release files

2.15.0

2 release files

2.14.0

2 release files

2.13.0

2 release files

2.12.0

2 release files

2.11.0

2 release files

2.10.0

2 release files

2.9.3

2 release files

2.9.2

2 release files

2.9.1

2 release files

2.9.0

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.3.0

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

1.6.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

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