init() options

Every parameter capsera.init() accepts, its default, and when to change it.

Most applications set two or three of these.

Connection

OptionDefaultNotes
api_key"dev"Your cap- key. The default is for local experiments and reports nothing useful.
endpoint"http://localhost:8000"Backend base URL. Set this for self-hosting.
env"development"Environment label on every event.

Default attribution

OptionDefaultNotes
agent_nameNoneFallback agent for calls with no scope, replacing unknown.
teamNoneFallback team.

Decorators and tag() override both.

Delivery

OptionDefaultNotes
flush_interval_ms500How often the worker ships a batch.
max_retries3Attempts per failed batch, with exponential backoff.
on_errorNoneCallback for delivery failures.

Lowering flush_interval_ms does not make your calls faster, because nothing waits on delivery. It makes events appear sooner at the cost of more requests. Raising it is reasonable for a high-volume service.

Budget enforcement

OptionDefaultNotes
enable_budget_enforcementTruePre-call budget check. On by default.
budget_check_timeout1.0Seconds to wait before allowing the call.

This is the one default that adds latency, because it performs a round trip to the backend before each provider call. When no budget matches the call, the result is "allowed" and the call proceeds.

To disable it:

capsera.init(api_key=..., enable_budget_enforcement=False)

The timeout fails open. If the check does not complete in time, the call is allowed.

Routing

OptionDefaultNotes
enable_routingFalseOff by default, because routing changes which model answers.
routing_rulesNoneLocal rules, merged with backend rules. Local wins on name.
routing_refresh_interval60Seconds between backend rule refreshes.
critical_task_typesNoneTask types exempt from cost-driven downgrades.

Use critical_task_types to protect work that must not be moved to a cheaper model:

capsera.init(
    api_key=...,
    enable_routing=True,
    critical_task_types=["legal-review", "medical-summary"],
)

See Routing.

Prompt analysis

OptionDefaultNotes
enable_prompt_analysisFalseStructural metrics only, never content.
prompt_size_threshold4000Token count above which a prompt is oversized.
on_oversized_promptNoneCallback receiving (tokens, threshold).

See Prompt analysis.

Diagnostics

OptionDefaultNotes
debugFalseOne INFO log line per intercepted call.

Useful while integrating, noisy in production.

A production example

import os

import capsera

capsera.init(
    api_key=os.environ["CAPSERA_API_KEY"],
    env=os.environ.get("APP_ENV", "development"),
    agent_name="api-server",
    team="platform",
    on_error=lambda exc: logging.warning("capsera delivery failed: %s", exc),
)

Everything else is left at its default: budget enforcement on, routing off, prompt analysis off, debug off.

Calling init() repeatedly

Safe. The patch is applied once per class and guarded, so a second call cannot record a call twice. Re-initialising flushes the previous emitter so queued events are delivered, then points new calls at the new configuration.

The full signature

This page covers the options worth a decision. For the complete parameter list in declaration order, with types and defaults, see Lifecycle functions.