Skip to main content

Configuration

The gateway reads one YAML file at startup. It has five top-level sections: model_list registers models, spanway_settings sets SDK level behaviour such as callbacks and parameter handling, router_settings controls load balancing, retries and fallbacks, general_settings configures the proxy server itself, and environment_variables sets environment variables before anything else loads. A few feature blocks sit beside them at the top level: files_settings and finetune_settings hold the provider credentials for batches and files and fine-tuning, assistant_settings names the provider account for the Assistants API, search_tools lists the web search tools keys can call, and pass_through_endpoints can sit under general_settings for custom pass-through routes. The settings reference lists their fields. Pass the file with --config config.yaml when you start the image, as in the quick start, or with the CONFIG_FILE_PATH environment variable.

model_list:
- model_name: claude-sonnet-5-5
spanway_params:
model: anthropic/claude-sonnet-5-5
api_key: os.environ/ANTHROPIC_API_KEY
model_info:
description: Default model for internal tools

spanway_settings:
drop_params: true
success_callback: ["langfuse"]

router_settings:
routing_strategy: simple-shuffle
num_retries: 2
fallbacks: [{"claude-sonnet-5-5": ["gpt-6.1-sol"]}]

general_settings:
master_key: os.environ/SPANWAY_MASTER_KEY
database_url: os.environ/DATABASE_URL

environment_variables:
LANGFUSE_HOST: https://cloud.langfuse.com

A real-world scenario​

A platform team keeps config.yaml in a Git repository with one file per provider under models/ pulled in with include. Secrets are os.environ/NAME references resolved from the company's secret manager, so the repository holds no keys. A pull request that adds a model runs the image with --config config.yaml --validate_config in CI, and the deployment rolls the gateway with the new file. Models that need to change between deploys are added from the Admin UI with STORE_MODEL_IN_DB=True, and the file stays the source of truth for everything else.

Secrets and environment references​

Any string value of the form os.environ/NAME is resolved when the config is loaded. The gateway first checks a configured secret manager and then the process environment, so the same reference works with AWS Secrets Manager, HashiCorp Vault or a plain environment variable. See secret managers. Never commit provider keys to the config file.

model_list​

Each entry has a public model_name, a spanway_params block that is passed to the provider call, and an optional model_info block with metadata. Several entries can share one model_name, which makes them deployments of one model group that the router load balances across.

KeyWhereMeaning
model_nameentryPublic name clients send in the model field.
modelspanway_paramsProvider prefix and upstream model, for example bedrock/us.anthropic.claude-sonnet-5-5.
api_key, api_base, api_versionspanway_paramsCredential and endpoint for this deployment.
rpm, tpmspanway_paramsRequests and tokens per minute this deployment can take, used by the router.
timeout, stream_timeout, max_retriesspanway_paramsPer-deployment timeouts and retries.
input_cost_per_token, output_cost_per_tokenspanway_paramsOverride bundled prices, see custom pricing.
id, mode, access_groups, base_modelmodel_infoStable deployment id, health check mode, access group names, and the base model used for cost lookup.

Provider-specific wildcard routing​

A wildcard entry forwards any model under a provider prefix without listing each model. The client sends the full provider path, such as anthropic/claude-haiku-5-5, and the gateway matches it to the entry whose model_name pattern fits. Credentials come from the matching entry.

model_list:
- model_name: "anthropic/*"
spanway_params:
model: "anthropic/*"
api_key: os.environ/ANTHROPIC_API_KEY
- model_name: "vertex_ai/*"
spanway_params:
model: "vertex_ai/*"
vertex_project: os.environ/VERTEXAI_PROJECT
vertex_location: global

Explicit entries take priority over wildcard entries, so you can register a few models by name and let a wildcard catch the rest. See wildcard routing for pattern rules and access control.

spanway_settings​

These keys set module level options of the SDK inside the gateway. Common ones are drop_params (drop parameters a provider does not support, see drop params), success_callback, failure_callback and callbacks (logging integrations, see logging), cache and cache_params (see caching), request_timeout, num_retries, set_verbose and json_logs.

structured_output_repair and structured_output_max_retries set the default for structured output repair. structured_output_repair is off by default. When it is repair, broken JSON in a reply is fixed locally at no cost, and retry and repair_and_retry ask the model again, which is another billed call each time. structured_output_max_retries is the most correction calls per request, from 0 to 5, and an unset value means 1.

MCP tool search defaults​

spanway_settings.ui_theme_config holds the Admin UI branding, logo_url, logo_url_dark and favicon_url, each a public http or https URL. The UI Theme page writes it, and you can set it here for a gateway built from a config file, see UI theme.

spanway_settings.mcp_tool_search holds the gateway wide defaults for tool search, which gives a model two small tools to find and call MCP tools instead of the full catalogue. Tool search itself is switched on per key or team. These defaults decide how a search ranks tools, and a key or team can override top_k and similarity_threshold. A proxy admin changes them here or on the Tool Search tab of MCP Servers.

KeyTypeDefaultMeaning
embedding_modelstringunsetA model group from model_list used to rank tools by meaning. Unset keeps keyword matching, which costs nothing. Set, each search costs one embedding call.
top_kint, 1 to 1005The most tools one search returns. A smaller top_k in the model's own call wins.
similarity_thresholdfloat, 0.0 to 1.00.0The lowest similarity a tool needs in semantic results. Higher returns fewer, closer matches. 0.0 means no cutoff.
core_toolslist of strings[]Tool names always returned first when the caller may use them. They do not count towards top_k.

Dynamic rate limiter settings​

spanway_settings.priority_reservation_settings tunes the dynamic rate limiter, which shares a busy model between priority classes and teams. It only applies with callbacks: ["dynamic_rate_limiter_v3"], and the priority pools in priority_reservation need a licence.

KeyTypeDefaultMeaning
default_priorityfloat0.25The share of a model a key without a priority in its metadata may use.
saturation_thresholdfloat, 0.0 to 1.00.50How full a model must be before each priority class is held to its reserved share. Below it, callers may borrow idle capacity.
saturation_check_cache_ttlint, seconds60How long each instance reuses the saturation it read from Redis.
team_borrow_capfloat, 0.0 to 1.0unsetThe largest share of a model one team may use, also while borrowing. Unset means no cap. A team's rate_limit_borrow_cap metadata can lower it, never raise it.
active_team_splitboolfalseWhen the model is busy, split each priority class evenly between the teams that sent it requests this minute. Off means first come, first served.

Environment variables for the admin MCP server​

The hosted admin MCP server is configured with environment variables, not with this file. They are SPANWAY_ENABLE_ADMIN_MCP (default false), SPANWAY_ADMIN_MCP_MIN_ROLE (default proxy_admin), SPANWAY_MCP_PUBLIC_URL (default PROXY_BASE_URL), SPANWAY_ADMIN_READ_ONLY (default false), SPANWAY_ADMIN_TOOLS (default all tools), SPANWAY_ADMIN_RESPONSE_VIEW (default full, compact in the standalone connector) and SPANWAY_ADMIN_SCHEMA_MODE (default full). The admin MCP page explains each one in plain words, with what on and off do.

PROXY_BASE_URL is the address people and clients use to reach the gateway, for example https://gateway.example.com. It is unset by default. When it is set, the gateway uses it to build every link it hands out, such as the MCP connect page link, OAuth redirect and metadata addresses and single sign-on redirects, so they point at your public address even behind a load balancer. When it is unset, links are built from the address of each incoming request, which is right for a gateway reached directly but can give an internal host name behind a proxy. Set it to a full http or https URL with a host. For MCP links, any other value is ignored with a warning in the log (PROXY_BASE_URL=... is not a valid http(s) URL ...) and the links fall back to the request address. Whoever runs the deployment sets it, once, to the public URL.

router_settings​

router_settings decides how the gateway spreads traffic across the deployments of a model, and what it does when a call fails. Every key below can also be changed on Settings, Router Settings unless the row says otherwise, and a key set here in config.yaml cannot be changed there (the save is refused with 400). Leaving a key out keeps its default.

KeyTypeDefaultWhat it does
routing_strategystringsimple-shuffleHow one deployment is picked: simple-shuffle, least-busy, usage-based-routing, usage-based-routing-v2, latency-based-routing, cost-based-routing or lar1, see routing.
routing_strategy_argsobject{}Options for the strategy, for example ttl and lowest_latency_buffer for latency based routing.
routing_groupslist[]Model groups that get their own strategy, including priority, see routing groups.
num_retriesint2Times a failed call is tried again on the same model group. Each retry is another billed call.
retry_afterint, seconds0Wait before a retry.
retry_policyobjectunsetRetry counts per error type, for example {"RateLimitErrorRetries": 3}.
model_group_retry_policyobject{}A retry policy per model group.
timeoutfloat, seconds6000Longest a call may run before it counts as a failure. Unset uses the gateway request timeout, 6000 seconds unless the REQUEST_TIMEOUT environment variable changes it. Fractions such as 0.5 are kept.
stream_timeoutfloat, secondsunsetLongest a streaming call may wait. Unset uses timeout.
fallbackslist[]Model groups to try when a whole group fails.
default_fallbackslistunsetFallbacks for every group without its own entry. Applied at the next start.
max_fallbacksint5Most fallback groups tried for one call before the last error is returned. The ROUTER_MAX_FALLBACKS environment variable changes this default.
context_window_fallbackslist[]Larger groups to try when the prompt is too long.
content_policy_fallbackslist[]Groups to try when a provider refuses on content policy.
context_fitbool, string or objectoffTrim conversations that do not fit the selected deployment's input window, see fit to context.
allowed_failsint3Left at 3, the built-in error rate rule decides when a deployment is paused (cooled down), see cooldowns. Any other value switches to counting, and the deployment is paused once its failures inside one cooldown_time window go over this number.
allowed_fails_policyobjectunsetAllowed failures per error type. Applied at the next start.
cooldown_timefloat, seconds5How long a paused deployment gets no traffic, and the window allowed_fails counts failures in. The DEFAULT_COOLDOWN_TIME_SECONDS environment variable changes this default.
disable_cooldownsboolfalseWhen true, failing deployments are never paused.
enable_weighted_failoverboolfalseWhen true with simple-shuffle, a failed call is retried on the group's other deployments before any fallback.
enable_pre_call_checksboolfalseWhen true, deployments whose context window is too small are skipped before the call.
optional_pre_call_checkslistunsetExtra checks before routing, such as prompt_caching, router_budget_limiting, session_affinity and enforce_model_rate_limits.
deployment_affinity_ttl_secondsint, seconds3600How long a caller stays on the same deployment when the deployment_affinity check is on. Applied at the next start.
model_group_affinity_configobjectunsetAffinity checks for single model groups. Applied at the next start.
enable_tag_filteringboolfalseWhen true, tagged requests only go to deployments with matching tags, see tag routing.
tag_filtering_match_anybooltrueWhen true, one matching tag is enough. When false, every tag must match.
tag_routing_prefixstring""Prefix that marks a request tag as a routing directive.
model_group_aliasobject{}Extra public names for existing model groups.
default_spanway_paramsobjectunsetRequest settings added to every call that does not set them. Applied at the next start.
default_max_parallel_requestsintunsetMost parallel calls per deployment when the deployment sets no limit. Applied at the next start.
provider_budget_configobjectunsetSpend cap per provider, see provider budgets. Applied at the next start.
enable_health_check_routingboolfalseWhen true, deployments the background health checks mark unhealthy get no traffic, see health. Applied at the next start.
health_check_staleness_thresholdint, secondstwice the health check intervalAge after which a health result is ignored. Applied at the next start.
health_check_ignore_transient_errorsboolfalseWhen true, a health check timeout or rate limit does not take a deployment out. Applied at the next start.
use_curated_data_termsboolfalseWhen true, provider data policy filters trust the curated provider terms, see provider preferences. No Admin UI control.
set_verboseboolfalseWhen true, the router writes detailed debug lines. Logs grow quickly, so turn it off afterwards. Applied at the next start.
redis_host, redis_port, redis_password, redis_urlstringunsetShared state for multiple gateway instances. No Admin UI control. redis_password and redis_url are never shown back by GET /router/settings.

See routing and reliability for how these interact.

general_settings​

general_settings holds server level options. The most used keys are master_key, database_url, database_connection_pool_limit, store_model_in_db, custom_auth, alerting, alert_types, background_health_checks, health_check_interval, max_parallel_requests, global_max_parallel_requests, max_request_size_mb, allowed_routes, ui_access_mode, pass_through_endpoints, store_prompts_in_spend_logs and maximum_spend_logs_retention_period. Each is described on the page for the feature it controls.

Splitting the config into several files​

A config can pull in other YAML files with include. Paths are resolved next to the file that declares them, and the included model_list entries are merged into the main list.

include:
- models/anthropic.yaml
- models/openai.yaml

general_settings:
master_key: os.environ/SPANWAY_MASTER_KEY

Validating a config​

Run the image with --config config.yaml --validate_config (shown in the steps below) to load the file and exit, which catches YAML errors, broken include files and model entries that fail to load in CI before a deploy. It does not check key names, so a misspelled or misplaced setting still passes. To change models without a restart, set STORE_MODEL_IN_DB=True and manage them through model management.

Step by step​

  1. Write the file with the sections you need and reference every secret as os.environ/NAME.

  2. Validate it before starting:

    docker run --rm -v "$PWD:/app/work" -w /app/work registry.spanway.ai/spanway/spanway-ai:2.0.0 --config config.yaml --validate_config

    Expected result: the command prints Spanway: config OK (N models) and exits 0. A file that is not valid YAML, or a model that fails to load, exits 1 with Spanway: config validation failed: and the reason. A misspelled key is not reported.

  3. Start the gateway and confirm the models were registered:

    curl http://localhost:4000/v1/models -H "Authorization: Bearer $SPANWAY_API_KEY"

    Expected result: one entry per distinct model_name, so two deployments of claude-sonnet-5-5 show once.

  4. Read the router and general settings the gateway is running with. Router Settings in the Admin UI shows the router_settings values with where each came from, and GET /router/settings returns the same:

    curl http://localhost:4000/router/settings -H "Authorization: Bearer $SPANWAY_API_KEY"
  5. To change models without a restart, set STORE_MODEL_IN_DB=True and use Models + Endpoints, Add model in the Admin UI or POST /model/new. The file keeps its own entries, the database adds to them.

Errors​

SymptomMeaningFix
--validate_config exits 1 with Spanway: config validation failed: ...The file is not valid YAML, an include file is missing, or a model entry failed to load.Fix the line or entry the message names.
A setting has no effect although --validate_config printed config OKThe key is misspelled or in the wrong section, for example routing_strategy under general_settings. The check does not look at key names.Move or fix the key, see the settings reference.
The gateway starts but a model is missing from /v1/modelsThe entry failed to load, usually a missing credential, and the startup log names it.Set the environment variable or secret the entry references.
os.environ/NAME is passed to the provider literallyThe secret manager and the environment both lack NAME.Set it, or add it to hosted_keys for the secret manager.
include path not foundIncluded paths are resolved next to the file that declares them.Use a path relative to the including file.
400 Invalid model name passed in model=... from a wildcard setupThe client sent a name the wildcard pattern does not match.Send the full provider path, for example anthropic/claude-haiku-5-5.