Skip to content

@ModelProvider

The @ModelProvider decorator ("@agboss/core/models") defines an application-level LLM gateway registered in @Application({ providers }). Every model string referenced by an @Agent, @Router, @Arbiter, @Judge, @Compaction, @InputGuardrail, @OutputGuardrail, or @PiiPolicy is matched at startup against the serves regular expressions of your registered @ModelProvider classes ([model.unserved] or [model.ambiguous-provider] if zero or multiple custom providers match).

@ModelProvider supports two transport modes ([model-provider.both-modes] if mixed):

  1. HTTP base URL mode (OpenRouterProvider / OpenAiCompatibleProvider): Configured with baseUrl / baseUrlField and optional apiKey (plus OpenRouter host and quantization pinning only, ignore, quantizations, allowFallbacks).
  2. Custom transport mode (implements ModelProviderHandler): Implements complete(request: ModelProviderRequest): Promise<ModelProviderResponse> with constructor DI (deps: [...]) for AWS Bedrock SDK (SigV4), Google Vertex AI, or corporate mTLS gateways while retaining every AGBoss gateway policy (@Budget pre-check & ledger, RateLimitRepository, 429 AIMD, retries, circuit breaker, PII masking, structured output answer tools, and mockLlm interception).

Every @ModelProvider class extends OpenRouterProvider, OpenAiCompatibleProvider, or implements ModelProviderHandler, and its name ends with -model-provider (class name ending with ModelProvider, [name.kind-suffix]):

Option Type Required Description
name string Yes Unique kebab-case identifier ending with -model-provider (e.g., "openrouter-model-provider").
description string Yes Human-readable summary of which models and upstream endpoint this provider serves.
serves readonly (string | RegExp)[] Yes Non-empty array of model names or regex patterns matching model IDs served by this provider ([/^moonshotai\//, /^anthropic\//]).
baseUrl string For HTTP providers Default upstream base URL (OPENROUTER_BASE_URL). Forbidden when implementing ModelProviderHandler ([model-provider.both-modes]).
baseUrlField string No (HTTP only) Optional field name on AppEnvironment (env.optional("OPENROUTER_BASE_URL")) that overrides baseUrl when set.
apiKey string No (HTTP only) Field name on AppEnvironment holding the secret("...") API key; omit for unauthenticated local model servers.
deps readonly Token[] No (ModelProviderHandler) Constructor dependencies (@Injectable() SDK clients, ApplicationContext, TenantContext, ExecutionContext) injected into custom transport providers.
timeout Milliseconds Yes Per-attempt request timeout (minutes(2)), passed via request.signal.
cost ModelCost Yes Cost calculation policy (ModelCost.fromResponse(), ModelCost.fromPrices(...), or ModelCost.free()).
reasoning Reasoning Yes Default reasoning mode (Reasoning.off(), Reasoning.on({ effort }), or Reasoning.modelDecides()).
promptCaching PromptCaching Yes Default prompt caching policy (PromptCaching.off(), PromptCaching.whereSupported(...)).
retryPolicy RetryPolicy Yes Per-call retry backoff (RetryPolicy.exponential({ maxAttempts, initialDelay, maxDelay, jitter, retryOn }) or RetryPolicy.none()).
rateLimitPolicy RateLimitPolicy No Cluster-wide concurrency (maxConcurrentCalls), RPM (perMinute), and tenant fairness (QueueBalancingStrategy.TenantRoundRobin) coordinated via RateLimitRepository.
circuitBreakerPolicy CircuitBreakerPolicy No Trips open across all instances when upstream fails ({ failureThreshold, window, openFor }), shifting app.checkReadiness() to HealthStatus.Degraded and activating fallbackModels.
only / ignore / quantizations / allowFallbacks OpenRouterProvider options No OpenRouter host and quantization pinning (only: ["Fireworks"], ignore: ["Inceptron"], quantizations: ["fp8", "bf16"], allowFallbacks: false) to prevent silent quantization degradation in production and evals.
Section titled “What related entities work with @ModelProvider?”
Related Entity Import Path Purpose
OpenRouterProvider & OpenAiCompatibleProvider "@agboss/core/models" Base classes for OpenRouter and OpenAI-compatible chat/decision model servers (OpenAI, vLLM, Ollama, LiteLLM).
ModelProviderHandler (complete(request)) "@agboss/core/models" Interface for custom SDK/transport gateways (AWS Bedrock, Vertex AI, corporate proxies) wrapped by all AGBoss FinOps, rate-limit, circuit-breaker, and PII policies.
ModelProviderFailureError "@agboss/core/models" Thrown inside complete(request) to report classified failures (ModelFailure.RateLimit with retryAfter, ModelFailure.Overloaded, ModelFailure.InvalidOutput, ModelFailure.InvalidToolArguments) to the retry and AIMD engines.
OpenRouterModelProvider & DecisionsModelProvider "@agboss/core/models" Built-in catch-all providers (serves: [/.*/] and [/^typesafe\/jev-/]) that automatically yield any model claimed by another @ModelProvider in @Application({ providers }) (unless explicitly replaced by subclassing extends OpenRouterModelProvider or extends DecisionsModelProvider).
RateLimitPolicy & QueueBalancingStrategy "@agboss/core/models" Configures maxConcurrentCalls, perMinute, and QueueBalancingStrategy (TenantRoundRobin, TenantLeastInFlight, TenantWeighted, Fifo).
RetryPolicy & CircuitBreakerPolicy "@agboss/core/models" Configures per-call exponential backoff and shared multi-instance circuit breaking.
ModelCost, Reasoning, PromptCaching "@agboss/core/models" Configures token pricing, thinking effort (ReasoningEffort), and KV prefix cache policies.
RateLimitRepository & SqliteRateLimitRepository "@agboss/core" Storage contract that coordinates concurrency slots, 429 cooldown windows, and circuit breaker state across worker processes.