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_ env reqwest - OpenCode Zen’s Messages-format endpoint from the environment variables
crate::providers::anthropic::wire::OPENCODEnames, on the shared reqwest client. - anthropic_
new reqwest - OpenCode Zen’s Messages-format endpoint with
api_key, on the shared reqwest client. - from_
env reqwest - OpenCode Zen from the environment variables
crate::providers::openai::wire::OPENCODEnames, on the shared reqwest client. - go_
anthropic_ from_ env reqwest - OpenCode Go’s Messages-format endpoint from the environment variables
crate::providers::anthropic::wire::OPENCODE_GOnames, on the shared reqwest client. - go_
anthropic_ new reqwest - OpenCode Go’s Messages-format endpoint with
api_key, on the shared reqwest client. - go_
from_ env reqwest - OpenCode Go from the environment variables
crate::providers::openai::wire::OPENCODE_GOnames, on the shared reqwest client. - go_new
reqwest - OpenCode Go with
api_key, on the shared reqwest client. - new
reqwest - OpenCode Zen with
api_key, on the shared reqwest client.