Providers¶
Accrue is provider-agnostic. It ships adapters for OpenAI, Anthropic, and Google, supports any OpenAI-compatible API, and exposes a protocol for custom providers.
OpenAI (default)¶
No extra install needed. OpenAI is the default provider, and gpt-6-luna the default model: an LLMStep without model= uses it.
from accrue import Pipeline, LLMStep
pipeline = Pipeline([
LLMStep("analyze",
fields={"summary": "Summarize the company"},
model="gpt-6-luna",
),
])
Set OPENAI_API_KEY in your environment or pass api_key= directly.
OpenAI uses the Responses API natively, which enables web search and structured outputs (json_schema with strict: true). When base_url is set, it falls back to Chat Completions for compatibility with third-party APIs.
Cached tokens: OpenAI caches long prompt prefixes automatically and reports the hit as cached_tokens inside its input count (newer SDKs also report cache_write_tokens). Accrue moves them into cache_read_tokens and cache_write_tokens, so prompt_tokens is the uncached input, the same split as Anthropic. total_tokens is unchanged.
Temperature: OpenAI reasoning models (the o-series, such as o3, and GPT-5 onwards, including the gpt-6-luna default) reject an explicit temperature with a 400. Accrue leaves it out for those model names, on the realtime and batch paths (where batch requests also send max_completion_tokens in place of max_tokens, which those models reject on Chat Completions), and logs a warning once if the dropped value was not 1.0. The retired -chat variants (gpt-5-chat-latest) still get it; chat-latest, which replaced them, rejects any value but the default and does not. The gate is by model name only: GPT-5.1 and later accept temperature when reasoning effort is none, so for that case pass provider_kwargs={"temperature": ..., "reasoning": {"effort": "none"}}, which still overrides.
Anthropic¶
from accrue import Pipeline, LLMStep
pipeline = Pipeline([
LLMStep("analyze",
fields={"summary": "Summarize the company"},
model="claude-sonnet-5-5",
),
])
The provider is auto-detected from the claude- model prefix. No explicit client= import needed.
Install: pip install "accrue[anthropic]"
Auth: Set ANTHROPIC_API_KEY (or pass api_key= to LLMStep).
Custom client (optional): For non-default Anthropic SDK options pass client=AnthropicClient(...) explicitly — overrides auto-detection.
Prompt caching: Accrue automatically adds cache_control: {"type": "ephemeral"} to system messages. No configuration required.
Anthropic reads a cached prefix only on an exact match, so Accrue splits every LLM prompt at the static/variable boundary and sends the two halves separately:
| Half | Contents | Varies per row? |
|---|---|---|
system (cached) |
Role, your system_prompt_header (or system_prompt), field spec key descriptions, output rules, and the <field_specifications> block |
No |
user |
<row_data>, <prior_results>, the task instruction, and the closing reminder |
Yes |
The first row of a step writes the cache entry (billed at 1.25x input); every subsequent row reads it at 0.1x. Savings therefore scale with how much of your prompt is static: a step with a large system_prompt_header and rich field specs saves most, a step whose prompt is almost entirely row data saves little or nothing (see the floor below).
Three consequences worth knowing:
- A prefix below the model's minimum is not cached at all. Anthropic caches a prefix only past a per-model floor, and the floor is not lower on newer models — it varies by model, not by generation:
| Minimum cacheable prefix | Models |
|---|---|
| 512 tokens | Opus 5 |
| 1024 tokens | Opus 4.8, Sonnet 5, Sonnet 4.6, Sonnet 4.5 |
| 2048 tokens | Opus 4.7 |
| 4096 tokens | Haiku 4.5, Opus 4.6, Opus 4.5 |
Under the floor, cache_control is silently ignored — no error, just zero cache tokens. Accrue's auto-generated system half is roughly 850 characters for a one-field step and 1,800 for a three-field step with enums, formats, and examples (order of a few hundred tokens), so on every model in the table caching does nothing until you add real static context — a substantial system_prompt_header (or system_prompt), or unusually rich field specs. Haiku 4.5 needs the most: a step has to clear 4096 tokens of static prefix before caching does anything at all. If result.cost reports zero cache write/read tokens on a small step, that is the floor, not a regression.
- Cache entries are scoped to the exact prefix, so changing system_prompt_header, field specs, or the model starts a fresh entry.
- With max_workers > 1 on a cold cache, the workers in the first wave all start before any entry exists, so each writes its own. The cache settles from the second wave onward.
Cache token accounting: Anthropic reports cache-creation and cache-read tokens separately from input_tokens. Accrue carries them as cache_write_tokens and cache_read_tokens on UsageInfo, aggregates them into StepUsage and CostSummary, and counts them in total_tokens, so cost reports reflect the real bill. The three input classes are priced differently (1.0x base input, 1.25x cache write, 0.1x cache read), so the cache fields stay separate from prompt_tokens. Providers and models that do not report cache tokens simply yield zeros.
Structured outputs: Uses constrained decoding (the Anthropic equivalent of json_schema). Auto-detected when using dict fields.
Schema size limit: Anthropic compiles the strict output schema into a decoding grammar and rejects grammars above an undocumented size ("Schema is too complex for compilation" / "compiled grammar is too large"; seen at around 30 fields with nested objects and enums). The failure is deterministic, so accrue raises one explanatory error and does not retry. To shrink the schema: reuse one nested class through a shared $ref rather than many sub-classes; use fewer Literal/enum fields and validate allowed values after parsing; flatten nested objects into strings your code parses; or split fields across more steps. Accrue does not try to predict the limit before the call.
Attachments: LLMStep(attachments="column") renders PDFs as Anthropic document blocks ahead of the user text. See the attachments guide.
Timeout: AnthropicClient(timeout=...) forwards a request timeout (seconds) to the SDK. You need it once max_tokens goes above roughly 21,000: the SDK estimates a non-streaming request's duration from max_tokens and refuses outright — ValueError: Streaming is required for operations that may take longer than 10 minutes — unless a non-default timeout was set on the client. Pass one explicitly for long-output steps:
from accrue import Pipeline, LLMStep
from accrue.providers import AnthropicClient
LLMStep("long_report",
fields={"report": "Write a full report"},
model="claude-sonnet-5-5",
max_tokens=32000,
client=AnthropicClient(timeout=1800.0),
)
Temperature: Anthropic API version 2026-10-21, which the anthropic SDK sends by default from 2.0.0, rejects temperature on every model (400 - temperature: Extra inputs are not permitted). On the older 2023-06-01 version, the Claude 5 family (claude-sonnet-5-5, claude-haiku-5-5, claude-opus-5, ...) and Claude Opus 4.7/4.8 reject it too. Accrue reads the version from the client and omits temperature wherever it would be rejected, on both the realtime and batch paths, so the model samples at its default of 1.0. If a realtime call is still rejected for its temperature, accrue retries it once without one and omits it for that model for the rest of the run. If the dropped value was something other than 1.0, a warning is logged once per pipeline run. To keep a lower temperature on a model that accepts one (Claude Sonnet 4.6, Opus 4.6, Haiku 4.5), pin the older version with provider_kwargs={"extra_headers": {"anthropic-version": "2023-06-01"}}. A provider_kwargs={"temperature": ...} is always sent as given.
Google¶
from accrue import Pipeline, LLMStep
pipeline = Pipeline([
LLMStep("analyze",
fields={"summary": "Summarize the company"},
model="gemini-3.5-flash-lite",
),
])
The provider is auto-detected from the gemini- model prefix. No explicit client= import needed.
Install: pip install "accrue[google]"
Auth: Set GOOGLE_API_KEY (or pass api_key= to LLMStep).
Custom client (optional): Pass client=GoogleClient(...) to override auto-detection with non-default options.
Grounding: Supports native Google Search grounding via the grounding parameter on LLMStep.
Token accounting: Thinking tokens (thoughts_token_count) count as completion_tokens, since Gemini bills them as output. Cached-content tokens (cached_content_token_count) are moved out of prompt_tokens into cache_read_tokens.
Retries: Gemini 429, 408 and 5xx errors are retried, carrying their status code; other 4xx errors are not.
OpenAI-compatible APIs¶
Any API that implements the OpenAI Chat Completions format works via base_url. This includes Ollama, Groq, Together, Fireworks, vLLM, and others.
# Ollama (local)
LLMStep("analyze", fields={...}, model="llama3", base_url="http://localhost:11434/v1")
# Groq
LLMStep("analyze", fields={...}, model="llama-3.3-70b-versatile",
base_url="https://api.groq.com/openai/v1", api_key="gsk_...")
# Together AI
LLMStep("analyze", fields={...}, model="meta-llama/Llama-3-70b-chat-hf",
base_url="https://api.together.xyz/v1", api_key="...")
When base_url is set, structured output auto-detection falls back to json_object (since third-party APIs may not support json_schema). Override with structured_outputs=True if your API supports it.
Behind a proxy that re-signs HTTPS¶
OpenAIClient, AnthropicClient and GoogleClient all take http_client=, the SDK's own async HTTP client. Build one that trusts the proxy's CA bundle instead of turning verification off, and pass api_key explicitly with it. Current SDKs (openai 3.x, anthropic 2.x, google-genai 3.x) use httpx2; older ones use httpx:
import os, ssl
try:
import httpx2 as httpx # current SDKs
except ImportError:
import httpx # older SDKs
from accrue import LLMStep
from accrue.providers import AnthropicClient
ssl_ctx = ssl.create_default_context(cafile="ca-bundle.pem")
client = AnthropicClient(
api_key=os.environ["ANTHROPIC_API_KEY"],
http_client=httpx.AsyncClient(verify=ssl_ctx),
)
LLMStep("enrich", fields={...}, model="claude-sonnet-5-5", client=client)
Feature comparison¶
| Feature | OpenAI | Anthropic | OpenAI-compatible | |
|---|---|---|---|---|
| Structured outputs | json_schema |
Constrained decoding | json_schema |
json_object |
| Grounding (web search) | Yes | Yes | Yes | No |
| Batch API | Yes | Yes | No | No |
| Prompt caching | No | Automatic | No | No |
Attachments (attachments=) |
Yes (PDF) | Yes | Yes (PDF) | No |
Custom providers¶
Implement the LLMClient protocol -- a single async method:
from accrue.providers import LLMClient, LLMResponse
from accrue.schemas.base import UsageInfo
from typing import Any
class MyClient:
"""Custom LLM provider adapter."""
async def complete(
self,
messages: list[dict[str, Any]],
model: str,
temperature: float,
max_tokens: int,
response_format: dict[str, Any] | None = None,
tools: list[dict[str, Any]] | None = None,
provider_kwargs: dict[str, Any] | None = None,
) -> LLMResponse:
# Call your API here
content = await my_api_call(messages, model, temperature, max_tokens)
return LLMResponse(
content=content,
usage=UsageInfo(input_tokens=100, output_tokens=50),
)
# Use it
LLMStep("analyze", fields={...}, client=MyClient())
The protocol is structural (duck typing). No inheritance required -- just implement the complete method with the right signature.
For batch API support, also implement the BatchCapableLLMClient protocol, which adds submit_batch(), poll_batch(), and cancel_batch() methods.
provider_kwargs¶
The provider_kwargs parameter is an escape hatch for provider-specific features not yet exposed as first-class parameters. The dict is merged into the API call: its top-level keys replace accrue's, except Anthropic's output_config and the OpenAI Responses API's text, which are merged key by key so accrue's structured-output format is kept.
# Anthropic extended thinking
LLMStep("deep_analysis",
fields={"analysis": "Detailed strategic analysis"},
model="claude-sonnet-5-5",
provider_kwargs={"thinking": {"type": "adaptive"}},
)
# Anthropic effort (merged into accrue's output_config, so the schema is kept)
LLMStep("cheap_tagging",
fields={"sector": "Industry sector"},
model="claude-haiku-5-5",
provider_kwargs={"output_config": {"effort": "low"}},
)
# OpenAI reduced effort
LLMStep("quick_check",
fields={"is_valid": "Is this a valid company?"},
provider_kwargs={"reasoning": {"effort": "low"}},
)
# OpenAI disable storage
LLMStep("sensitive",
fields={"pii_check": "Check for PII"},
provider_kwargs={"store": False},
)
provider_kwargs works for both realtime and batch execution. On native OpenAI, settings that Chat Completions (batch) and Responses (realtime) spell differently work in either spelling (details). They are part of the cache key, so changing them re-runs the step.
Gotchas¶
- Anthropic and Google require separate installs (
accrue[anthropic],accrue[google]). Import errors are deferred to instantiation, so you get a clear error message at runtime, not at import time. - When using
base_url, the OpenAI adapter switches from Responses API to Chat Completions. Features that rely on Responses API (native web search) are not available. - With grounding, structured outputs stay on for OpenAI and Anthropic. Google falls back to JSON mode.
- The
client=parameter overridesapi_key=andbase_url=. If you pass a pre-configured client, those other parameters are ignored.