1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! 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`](crate::catalog::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`](crate::providers::openai::OpenAI::completion)
//! chooses between by the catalog (a model it does not list goes to Chat
//! Completions; name another route with
//! [`with_route`](crate::providers::openai::OpenAIConfig::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`](crate::completion::GenerationOptions::cache_key), or a fresh
//! id without one. Set one key per conversation, so Go routes its turns
//! together and reuses their prompt cache.
//!
//! ```no_run
//! use rig_core::catalog::Catalog;
//! use rig_core::providers::opencode;
//!
//! # fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let haiku = Catalog::builtin().connect("opencode/claude-haiku-5-5")?;
//! let glm = opencode::go_from_env()?.completion("glm-5.3");
//! # let _ = (haiku, glm);
//! # Ok(())
//! # }
//! ```
/// Zen's provider key: the dialect name, a reply's `Origin::provider` and
/// the catalog vendor.
pub const ZEN: &str = "opencode";
/// Go's provider key.
pub const GO: &str = "opencode-go";
/// The header Go routes a conversation's requests together by.
pub const SESSION_HEADER: &str = "x-opencode-session";
crateopenai_vendor!;
crateopenai_vendor!;
crateanthropic_vendor!;
crateanthropic_vendor!;