feat(claude): add configurable API base URL via --anthropic-url

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 10:28:44 +02:00
parent 934566879e
commit b7aa458e40
4 changed files with 11 additions and 3 deletions

View File

@@ -61,7 +61,7 @@ pub async fn run(cli: &Cli) -> Result<()> {
// Init clients // Init clients
let swym = SwymClient::new(&cli.swym_url)?; let swym = SwymClient::new(&cli.swym_url)?;
let claude = ClaudeClient::new(&cli.anthropic_key, &cli.model); let claude = ClaudeClient::new(&cli.anthropic_key, &cli.anthropic_url, &cli.model);
// Check candle coverage for all instruments // Check candle coverage for all instruments
info!( info!(

View File

@@ -6,6 +6,7 @@ use serde_json::Value;
pub struct ClaudeClient { pub struct ClaudeClient {
client: Client, client: Client,
api_key: String, api_key: String,
api_url: String,
model: String, model: String,
} }
@@ -41,7 +42,7 @@ pub struct Usage {
} }
impl ClaudeClient { impl ClaudeClient {
pub fn new(api_key: &str, model: &str) -> Self { pub fn new(api_key: &str, api_url: &str, model: &str) -> Self {
let client = Client::builder() let client = Client::builder()
.timeout(std::time::Duration::from_secs(120)) .timeout(std::time::Duration::from_secs(120))
.build() .build()
@@ -49,6 +50,7 @@ impl ClaudeClient {
Self { Self {
client, client,
api_key: api_key.to_string(), api_key: api_key.to_string(),
api_url: api_url.to_string(),
model: model.to_string(), model: model.to_string(),
} }
} }
@@ -66,9 +68,10 @@ impl ClaudeClient {
messages: messages.to_vec(), messages: messages.to_vec(),
}; };
let url = format!("{}/v1/messages", self.api_url.trim_end_matches('/'));
let resp = self let resp = self
.client .client
.post("https://api.anthropic.com/v1/messages") .post(&url)
.header("x-api-key", &self.api_key) .header("x-api-key", &self.api_key)
.header("anthropic-version", "2023-06-01") .header("anthropic-version", "2023-06-01")
.header("content-type", "application/json") .header("content-type", "application/json")

View File

@@ -17,6 +17,10 @@ pub struct Cli {
#[arg(long)] #[arg(long)]
pub anthropic_key: String, pub anthropic_key: String,
/// Anthropic API base URL.
#[arg(long, default_value = "https://api.anthropic.com")]
pub anthropic_url: String,
/// Claude model to use for strategy generation. /// Claude model to use for strategy generation.
#[arg(long, default_value = "claude-sonnet-4-20250514")] #[arg(long, default_value = "claude-sonnet-4-20250514")]
pub model: String, pub model: String,

View File

@@ -20,6 +20,7 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("scout starting"); tracing::info!("scout starting");
tracing::info!(" swym API: {}", cli.swym_url); tracing::info!(" swym API: {}", cli.swym_url);
tracing::info!(" claude API: {}", cli.anthropic_url);
tracing::info!(" model: {}", cli.model); tracing::info!(" model: {}", cli.model);
tracing::info!(" iterations: {}", cli.max_iterations); tracing::info!(" iterations: {}", cli.max_iterations);
tracing::info!(" instruments: {:?}", cli.instruments); tracing::info!(" instruments: {:?}", cli.instruments);