Skip to main content

Config

Struct Config 

Source
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: LogFormat

How each finished request is printed to stderr: text, json or off.

§ui: bool

Whether 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: NetworkConfig

How the gateway reaches providers and tool servers: through which proxy, trusting which certificates besides the system’s.

§plugins: PluginsConfig

The 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

Source

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.

Source

pub fn from_value(value: Value) -> Result<Config, Error>

Structured configuration for language bindings, with secret-safe errors.

Source

pub fn load(path: impl AsRef<Path>) -> Result<Config, Error>

The configuration in the file at path.

Source

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.

Source

pub fn discover(path: Option<&Path>) -> Result<Config, Error>

path if given, else ./gateway.toml, else from_env.

Source

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.

Source

pub fn source(&self) -> &Source

Where it came from.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more