Skip to main content

adk_model/opencode/
service.rs

1use super::OpenCodeApi;
2
3/// OpenCode service to use. Go and Zen have separate endpoints and model routes.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum OpenCodeService {
7    /// Subscription-based coding service.
8    Go,
9    /// Pay-as-you-go model gateway.
10    Zen,
11}
12
13impl OpenCodeService {
14    /// Official base URL, including the API version.
15    pub fn base_url(self) -> &'static str {
16        match self {
17            Self::Go => "https://opencode.ai/zen/go/v1",
18            Self::Zen => "https://opencode.ai/zen/v1",
19        }
20    }
21
22    pub(super) fn provider(self) -> &'static str {
23        match self {
24            Self::Go => "opencode-go",
25            Self::Zen => "opencode",
26        }
27    }
28
29    /// API from the published endpoint table, or `None` for an unknown model.
30    ///
31    /// Sources: <https://opencode.ai/docs/go/#endpoints> and
32    /// <https://opencode.ai/docs/zen/#endpoints>. Unknown models require
33    /// [`super::OpenCodeConfig::with_api`].
34    ///
35    /// # Example
36    ///
37    /// ```
38    /// use adk_model::opencode::{OpenCodeApi, OpenCodeService};
39    ///
40    /// assert_eq!(OpenCodeService::Go.api("minimax-m3"), Some(OpenCodeApi::Messages));
41    /// assert_eq!(OpenCodeService::Zen.api("minimax-m3"), Some(OpenCodeApi::ChatCompletions));
42    /// ```
43    pub fn api(self, model: &str) -> Option<OpenCodeApi> {
44        match (self, model) {
45            (
46                Self::Go,
47                "grok-4.7"
48                | "grok-4.6"
49                | "gpt-6-luna"
50                | "gpt-5.6-luna"
51                | "muse-spark-1.3-contributor"
52                | "muse-spark-1.2-contributor",
53            ) => Some(OpenCodeApi::Responses),
54            (
55                Self::Go,
56                "minimax-m3" | "minimax-m2.7" | "minimax-m2.5" | "qwen3.8-max" | "qwen3.8-flash"
57                | "qwen3.7-max" | "qwen3.7-plus" | "qwen3.6-plus",
58            ) => Some(OpenCodeApi::Messages),
59            (
60                Self::Go,
61                "glm-5.3-flash"
62                | "glm-5.3"
63                | "glm-5.2"
64                | "glm-5.1"
65                | "kimi-k3"
66                | "kimi-k2.7-code"
67                | "kimi-k2.6"
68                | "longcat-2.0"
69                | "deepseek-v4.1-flash"
70                | "deepseek-v4-pro"
71                | "deepseek-v4-flash"
72                | "deepseek-v4-flash-vision-exp"
73                | "mimo-v2.6-flash"
74                | "mimo-v2.6-pro"
75                | "mimo-v2.5"
76                | "mimo-v2.5-pro"
77                | "hy4-preview"
78                | "hy3"
79                | "space-bunny-free"
80                | "longcat-2.5-preview-free",
81            ) => Some(OpenCodeApi::ChatCompletions),
82            (
83                Self::Zen,
84                "gpt-6-astra"
85                | "gpt-6.1-sol"
86                | "gpt-6-sol"
87                | "gpt-6-luna"
88                | "gpt-5.6-sol"
89                | "gpt-5.6-terra"
90                | "gpt-5.6-luna"
91                | "gpt-5.5"
92                | "gpt-5.5-pro"
93                | "gpt-5.4"
94                | "gpt-5.4-pro"
95                | "gpt-5.4-mini"
96                | "gpt-5.4-nano"
97                | "gpt-5.3-codex"
98                | "gpt-5.3-codex-spark"
99                | "gpt-5.2"
100                | "gpt-5.2-codex"
101                | "gpt-5.1"
102                | "gpt-5.1-codex"
103                | "gpt-5.1-codex-max"
104                | "gpt-5.1-codex-mini"
105                | "gpt-5"
106                | "gpt-5-codex"
107                | "gpt-5-nano"
108                | "grok-4.7"
109                | "grok-4.6"
110                | "grok-4.5"
111                | "grok-build-0.1"
112                | "muse-spark-1.3"
113                | "muse-spark-1.2"
114                | "muse-spark-1.3-contributor-free"
115                | "muse-ember-1.0"
116                | "muse-wonder-1.0",
117            ) => Some(OpenCodeApi::Responses),
118            (
119                Self::Zen,
120                "claude-fable-5-2" | "claude-fable-5-1" | "claude-fable-5" | "claude-opus-5-5"
121                | "claude-opus-5" | "claude-sonnet-5-5" | "claude-haiku-5-5" | "claude-opus-4-8"
122                | "claude-opus-4-7" | "claude-opus-4-6" | "claude-opus-4-5" | "claude-sonnet-5"
123                | "claude-sonnet-4-6" | "claude-sonnet-4-5" | "claude-haiku-4-5" | "qwen3.8-flash"
124                | "qwen3.7-max" | "qwen3.7-plus" | "qwen3.6-plus" | "qwen3.5-plus",
125            ) => Some(OpenCodeApi::Messages),
126            (
127                Self::Zen,
128                "gemini-4-carbon"
129                | "gemini-4-argon"
130                | "gemini-4-hydrogen"
131                | "gemini-3.8-flash"
132                | "gemini-3.7-flash"
133                | "gemini-3.6-flash"
134                | "gemini-3.5-flash"
135                | "gemini-3.5-flash-lite"
136                | "gemini-3.1-pro"
137                | "gemini-3-flash",
138            ) => Some(OpenCodeApi::GenerateContent),
139            (
140                Self::Zen,
141                "qwen3.8-max"
142                | "mistral-large-4"
143                | "deepseek-v4.1-flash"
144                | "deepseek-v4-pro"
145                | "deepseek-v4-flash"
146                | "deepseek-v4-flash-vision-exp"
147                | "minimax-m3"
148                | "minimax-m2.7"
149                | "minimax-m2.5"
150                | "glm-5.3-flash"
151                | "glm-5.3"
152                | "glm-5.2"
153                | "glm-5.1"
154                | "glm-5"
155                | "kimi-k2.5"
156                | "kimi-k2.6"
157                | "kimi-k2.7-code"
158                | "kimi-k3"
159                | "big-pickle"
160                | "space-bunny-free"
161                | "longcat-2.5-preview-free"
162                | "mimo-v2.6-flash-free"
163                | "mimo-v2.5-free"
164                | "ling-3.0-flash-fin-free"
165                | "nemotron-3-ultra-free"
166                | "nemotron-3.5-lightning-free",
167            ) => Some(OpenCodeApi::ChatCompletions),
168            _ => None,
169        }
170    }
171}