Skip to main content

Module gateway

Module gateway 

Source
Expand description

The AI Gateway, as a developer’s agent uses it: the console issues the developer a short-lived personal key for a project, and the agent calls the LLM gateway with it.

A new personal key revokes the developer’s previous one for that project, so a key is kept (in visdom’s own config directory, readable by the user only) and reused until shortly before it expires: sessions started side by side share it instead of cutting each other off. A kept key belongs to the account it was issued for and is not handed to another.

A subscription key (billing = subscription) is the other kind: it only works with the developer’s own Claude subscription token, lives about 30 days, and a new one revokes nothing. Claude Code gets it once, in a header fixed when it starts, so it is renewed a week before it expires, and the older ones are kept until they expire for visdom logout to revoke.

Structs§

ConsoleSettings
What the console’s settings say about the gateway.
EnsuredKey
A key from ensure_key.
IssuedKey
A personal key as issued.
KeptKey
A kept key, as visdom logout revokes it.
KeyStore
The personal keys visdom holds, one per console, project and account.
KeyStoreLock
Held while a key is looked up, issued and stored; released when dropped.
ModelsError
Why the LLM gateway’s models could not be listed.
OpenProject
A project the developer may issue themselves a personal key for.
ProjectModel
One alias of a project’s allow-list, as GET /api/me/keys lists it.

Enums§

SubscriptionTraffic
Whether the gateway takes calls paid by a Claude subscription, as its console publishes it (subscriptionTraffic in GET /api/settings).

Constants§

MIN_KEY_SECONDS_LEFT
A key with less than this left is replaced rather than handed out.
MIN_SUBSCRIPTION_KEY_SECONDS_LEFT
A subscription key with less than this left is replaced rather than handed out: a session started with it keeps it to its end. (Of a key that lives shorter than twice this, half its life.)
SUBSCRIPTION_TRAFFIC_DENIED
The code the console and the gateway refuse subscription traffic with while the deployment denies it.

Functions§

account_of
Whose key it is: the issuer and subject of the developer’s access token. A key is the person’s, so one kept for somebody else who logged in on this machine before must not be handed out. Empty for a token that is not a readable JWT, which then cannot be told apart from another such token.
console_settings
The LLM gateway’s public address and whether it takes subscription traffic, from the console’s settings.
ensure_key
The developer’s key for project_id: the stored one while it lasts, else a new one, which is then stored (a key that cannot be stored is an error). rejected is a key the gateway no longer takes (revoked by a newer one issued elsewhere): the stored key is used only if it is another one.
issue_key
Issue the developer a personal key of the kind billing for project_id. An ordinary key revokes their previous ordinary one for that project; a subscription key revokes nothing.
key_store_path_in
models
The model aliases key may call. This is also the proof that the LLM gateway answers and takes the key, before an agent is pointed at it.
open_projects
The projects the developer may issue a personal key for.
pick_model
The model alias an agent should ask for: the configured one, else the first alias that looks made for that agent, else none (the agent’s own default, which the project must then allow).
pick_project
The project to use: the configured one (its slug, id or name), else the only one there is. Otherwise the choice is the developer’s, and the error names what to choose from.
revoke_kept
Revoke at their consoles the kept keys of the person whose access token is token (on visdom logout, before the store is cleared). What could not be revoked is returned as warnings; such a key stays valid at the gateway until it expires. Keys of another account are not this token’s to revoke.
revoke_key
Revoke the developer’s key id at the console. A key the console no longer has (expired, or revoked already) is gone, which is what was asked.