pub struct Config {Show 17 fields
pub listen: Option<SocketAddr>,
pub body_limit: Option<usize>,
pub ws_message_limit: Option<usize>,
pub models: IndexMap<String, Model>,
pub prices: Option<IgnoredAny>,
pub shutdown_grace: Option<Duration>,
pub client_keys: Vec<ClientKey>,
pub log: LogFormat,
pub ui: bool,
pub providers: IndexMap<String, ProviderConfig>,
pub formats: Option<Vec<String>>,
pub routes: IndexMap<String, RouteConfig>,
pub tools: IndexMap<String, McpConfig>,
pub mcp: Option<IgnoredAny>,
pub cors: Option<CorsConfig>,
pub network: NetworkConfig,
pub plugins: PluginsConfig,
/* private fields */
}Expand description
A gateway’s configuration, as gateway.toml writes it.
Fields§
§listen: Option<SocketAddr>Where to listen, as host:port (a name is resolved), :port or a
bare port (on 127.0.0.1); 127.0.0.1:8080 if unset.
body_limit: Option<usize>The most bytes of a client’s request, and of a provider’s answer
held at once, past which the request fails 413 or the answer 502; a
number of bytes or a size such as 32MiB; 32 MiB if unset.
ws_message_limit: Option<usize>The largest WebSocket message of a session, from the client or the
provider, past which the session ends (close 1009); a number of
bytes or a size such as 16MiB; 16 MiB if unset.
models: IndexMap<String, Model>Models declared by provider/model, each a card (pricing,
display_name, context_window, capabilities, …) laid over what
the provider’s list says of it, or the whole of what is known of a
model it does not list. A call’s cost is its model’s pricing.
prices: Option<IgnoredAny>Retired: models, each with its pricing. Refused with how.
shutdown_grace: Option<Duration>How long open responses and end hooks get, together, after a stop
signal, before they are cut: seconds, or a duration such as 30s,
2m or 500ms; 30 s if unset.
client_keys: Vec<ClientKey>Client keys, literal or env:NAME, each alone or as
{ name, key }. When set, every request needs one; it is consumed
by the gateway and never sent to a provider. A request is logged
under its key’s name (key-1, key-2… for a key without one).
log: LogFormatHow each finished request is printed to stderr: text, json or
off.
ui: boolWhether the web UI and its admin API are served under /ui/.
providers: IndexMap<String, ProviderConfig>Providers by name, in order: the first serving a kind is that kind’s default.
formats: Option<Vec<String>>The formats served to clients, by name, tried in order. Unset:
openai-chat, anthropic-messages, and every format of another
kind some provider speaks, except passthrough. Serve
passthrough last to relay every other request unread to the
provider of format passthrough, whose base_url is then the
vendor’s origin. Clients of a format no other translates,
passthrough or a session’s, go to the one provider of that format.
routes: IndexMap<String, RouteConfig>Model routes by the model name clients ask for, or a glob of names
such as llama-*: where each goes, and how its candidates are
picked, retried and raced. An exact name is tried first, then a
provider/model name, then the globs in order, then each vendor’s
own model names, then the kind’s default.
tools: IndexMap<String, McpConfig>Tool servers by name, each served to clients over MCP at
/mcp/{name}: an MCP server at a streamable-HTTP url or run as a
command, or a tool vendor’s HTTP API. Name mcp in formats if
that lists formats.
mcp: Option<IgnoredAny>Retired: tools. Refused with how.
cors: Option<CorsConfig>Which web pages may call the gateway from a browser; none if unset.
network: NetworkConfigHow the gateway reaches providers and tool servers: through which proxy, trusting which certificates besides the system’s.
plugins: PluginsConfigThe compiled-in plugins, each configured under its name. The gateway runs them in an order of its own, whatever the order here.
Implementations§
Source§impl Config
impl Config
Sourcepub fn parse(text: &str) -> Result<Config, Error>
pub fn parse(text: &str) -> Result<Config, Error>
A configuration from TOML text. Errors omit source excerpts, which may contain credentials, while retaining the line and column.
Sourcepub fn from_value(value: Value) -> Result<Config, Error>
pub fn from_value(value: Value) -> Result<Config, Error>
Structured configuration for language bindings, with secret-safe errors.
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Config, Error>
pub fn load(path: impl AsRef<Path>) -> Result<Config, Error>
The configuration in the file at path.
Sourcepub fn from_env() -> Result<Config, Error>
pub fn from_env() -> Result<Config, Error>
A configuration with no file: a provider for every vendor whose key
is in the environment (OPENAI_API_KEY, ANTHROPIC_API_KEY, …;
Ollama if OLLAMA_HOST is set). RESPAN_<VENDOR>_BASE_URL moves a
vendor’s base URL. Err if there is none. Each tool vendor whose
key is there (LINKUP_API_KEY, …) is a tool server of its name,
and /mcp fronts them; the tool loop stays off.
Sourcepub fn discover(path: Option<&Path>) -> Result<Config, Error>
pub fn discover(path: Option<&Path>) -> Result<Config, Error>
path if given, else ./gateway.toml, else
from_env.
Sourcepub fn proxy(vendor: ProxyVendor, url: Option<&str>) -> Config
pub fn proxy(vendor: ProxyVendor, url: Option<&str>) -> Config
The configuration of proxy: one vendor at url (its public API if
None), no keys of its own, its chat format and every other request
relayed, with each client’s credentials: the chat format writes the
client’s request in its own spec, and passthrough relays the rest
byte for byte.