MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / chat

Method chat

crates/opencode-provider/src/openrouter.rs:175–201  ·  view source on GitHub ↗
(&self, request: ChatRequest)

Source from the content-addressed store, hash-verified

173 }
174
175 async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> {
176 let url = self
177 .config
178 .base_url
179 .as_deref()
180 .unwrap_or(OPENROUTER_API_URL);
181
182 let response = self
183 .client
184 .post(url)
185 .headers(self.build_headers())
186 .json(&request)
187 .send()
188 .await
189 .map_err(|e| ProviderError::NetworkError(e.to_string()))?;
190
191 if !response.status().is_success() {
192 let status = response.status();
193 let body = response.text().await.unwrap_or_default();
194 return Err(ProviderError::ApiError(format!("{}: {}", status, body)));
195 }
196
197 response
198 .json()
199 .await
200 .map_err(|e| ProviderError::ApiError(e.to_string()))
201 }
202
203 async fn chat_stream(&self, request: ChatRequest) -> Result<StreamResult, ProviderError> {
204 let url = self

Callers

nothing calls this directly

Calls 5

ApiErrorEnum · 0.50
sendMethod · 0.45
build_headersMethod · 0.45
statusMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected