BoundaryML/baml · error

PostHog returned {status}

Error message

PostHog returned {status}

What it means

`post_event` POSTs the feedback event to the PostHog `/capture/` endpoint and bails with this message when the HTTP response status is not a success (non-2xx). The status code is interpolated into the message (e.g. "PostHog returned 401 Unauthorized").

Source

Thrown at baml_language/crates/baml_cli/src/feedback_command.rs:920

            "$set": { "email": email },
        },
    });
    let _ = post_event(&body);
}

fn post_event(body: &Value) -> Result<()> {
    let api_key = body["api_key"].as_str().unwrap_or("");
    if api_key.trim().is_empty() {
        anyhow::bail!("This build has no PostHog key configured.");
    }
    let resp = auth::http_client()
        .post(format!("{}/capture/", posthog_host().trim_end_matches('/')))
        .json(body)
        .send()
        .context("Failed to reach PostHog")?;
    let status = resp.status();
    if !status.is_success() {
        anyhow::bail!("PostHog returned {status}");
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    fn send_args(
        title: Option<&str>,
        description: Option<&str>,
        input: Option<&str>,
    ) -> FeedbackInner {
        FeedbackInner {
            action: None,
            title: title.map(str::to_string),
            description: description.map(str::to_string),
            input: input.map(str::to_string),

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Check the status in the message: 401/403 means the API key is wrong; 5xx means PostHog-side trouble.
  2. Retry later if the status is 5xx — the failure is transient.
  3. Verify the PostHog project API key baked into the build is still valid.
  4. If using a self-hosted/custom posthog_host, confirm the instance is reachable and serving /capture/.
Defensive patterns

Strategy: retry

Try / catch

match post_event(&body) {
  Err(e) if e.to_string().contains("5") => schedule_retry(&body), // 5xx: retry later
  Err(e) => eprintln!("PostHog error: {e}"),
  Ok(()) => {}
}

Prevention

When it happens

Trigger: PostHog responds with 401/403 (bad key), 4xx (malformed capture payload), or 5xx (service outage) to the POST to `{posthog_host}/capture/`.

Common situations: PostHog outage or degraded service, an invalid/revoked project API key, a proxy or corporate firewall rewriting the response, or a custom PostHog host (self-hosted) that is misconfigured.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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