Skip to main content

Module opencode

Module opencode 

Source
Expand description

OpenCode Zen and Go: gateways that serve each model on one of three APIs, Chat Completions, Responses or Anthropic’s Messages.

Which API serves a model is in the model catalog, so Catalog::connect reaches each one on its own. The constructors here build one client per format: from_env and new for Zen’s Chat Completions and Responses, which OpenAI::completion chooses between by the catalog (a model it does not list goes to Chat Completions; name another route with with_route), and anthropic_from_env and anthropic_new for its Messages models. A Messages model asked of the first client goes to Chat Completions, which does not serve it. The go_ constructors are Go’s. Both read OPENCODE_API_KEY. Zen’s free models answer only OpenCode’s own client. The Messages endpoints list no models, so list them through the first client. Neither client checks a key without spending tokens.

Go refuses a request without an x-opencode-session header, which carries the request’s cache_key, or a fresh id without one. Set one key per conversation, so Go routes its turns together and reuses their prompt cache.

use rig_core::catalog::Catalog;
use rig_core::providers::opencode;

let haiku = Catalog::builtin().connect("opencode/claude-haiku-5-5")?;
let glm = opencode::go_from_env()?.completion("glm-5.3");

Functions§

anthropic_from_envreqwest
OpenCode Zen’s Messages-format endpoint from the environment variables crate::providers::anthropic::wire::OPENCODE names, on the shared reqwest client.
anthropic_newreqwest
OpenCode Zen’s Messages-format endpoint with api_key, on the shared reqwest client.
from_envreqwest
OpenCode Zen from the environment variables crate::providers::openai::wire::OPENCODE names, on the shared reqwest client.
go_anthropic_from_envreqwest
OpenCode Go’s Messages-format endpoint from the environment variables crate::providers::anthropic::wire::OPENCODE_GO names, on the shared reqwest client.
go_anthropic_newreqwest
OpenCode Go’s Messages-format endpoint with api_key, on the shared reqwest client.
go_from_envreqwest
OpenCode Go from the environment variables crate::providers::openai::wire::OPENCODE_GO names, on the shared reqwest client.
go_newreqwest
OpenCode Go with api_key, on the shared reqwest client.
newreqwest
OpenCode Zen with api_key, on the shared reqwest client.