BoundaryML/baml · error

Failed to fetch: {url}

Error message

Failed to fetch: {url}

What it means

The tracing API wrapper's `post` method sends an authenticated JSON POST to the BAML event/logging endpoint. If the HTTP client fails to execute the request at all (connection failure, DNS error, TLS problem, etc.), the `let-else` bails with 'Failed to fetch: {url}' — this fires before any HTTP status is available.

Source

Thrown at engine/baml-runtime/src/tracing/api_wrapper/mod.rs:144

    host_name: String,
    log_redaction_enabled: bool,
    log_redaction_placeholder: String,
    pub max_log_chunk_chars: usize,
}

impl CompleteAPIConfig {
    pub(self) async fn post<T: DeserializeOwned>(&self, path: &str, body: &Value) -> Result<T> {
        let url = format!("{}/{}", self.base_url, path);

        let req = self
            .client
            .post(&url)
            .json(body)
            .bearer_auth(&self.api_key)
            .build()?;

        let Ok(res) = self.client.execute(req).await else {
            return Err(anyhow::anyhow!("Failed to fetch: {url}"));
        };
        let status = res.status();
        let body = res.text().await?;

        if !status.is_success() {
            return Err(anyhow::anyhow!(
                "Failed to submit BAML log: {url}. Status: {status}\nBody: {body}"
            ));
        }

        match serde_json::from_str::<T>(&body) {
            Ok(v) => Ok(v),
            Err(e) => Err(anyhow::anyhow!(
                "Failed to parse response: {url}. Status: {status}\nBody: {body} \nError: {:?}",
                e
            )),
        }
    }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Verify the configured BOUNDARY/collector URL is reachable: `curl -v <url>` from the same machine.
  2. Check network connectivity, DNS, and proxy settings (HTTP_PROXY/HTTPS_PROXY) for the environment running BAML.
  3. Confirm the API endpoint host/port and TLS setup (correct scheme https vs http, correct port).

Example fix

// before (unreachable collector)
BOUNDARY_URL=http://localhost:9999   // nothing listening
// after
BOUNDARY_URL=http://localhost:7287   // correct, running collector
Defensive patterns

Strategy: retry

Validate before calling

// Shell: reachability pre-check before enabling tracing submission
curl -fsS --max-time 5 "$BOUNDARY_URL" >/dev/null || { echo "BOUNDARY_URL unreachable: $BOUNDARY_URL"; }

Try / catch

// Rust: retry transient fetch failures with backoff
for attempt in 0..3 {
    match wrapper.post(&url, &body).await {
        Ok(v) => break,
        Err(e) if e.to_string().contains("Failed to fetch") && attempt < 2 => {
            tokio::time::sleep(Duration::from_millis(500 * (attempt + 1))).await;
        }
        Err(e) => return Err(e),
    }
}

Prevention

When it happens

Trigger: Any transport-level failure during `self.client.execute(req)` in post(): the collector URL host is unreachable, network is down, DNS resolution fails, TLS handshake fails, or the request could not be constructed and the execute future returns Err.

Common situations: BOUNDARY_ collector URL pointing to a nonexistent host or closed port; corporate proxy/firewall blocking the endpoint; running locally (or in a CI job) without network access while the tracer tries to submit a session.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/1274c36125ddae05. Report an issue: GitHub.