sigoden/aichat · error

Invalid application_default_credentials.json

Error message

Invalid application_default_credentials.json

What it means

Validation failure when parsing Google application_default_credentials.json: the file exists and was read successfully, but its JSON lacks required fields (client_id, client_secret, refresh_token) or they are not strings — i.e. the file is present but not a valid ADC file (wrong file, corrupted, or a placeholder).

Solutions

  1. Regenerate credentials with 'gcloud auth application-default login' so the file contains client_id, client_secret, and refresh_token
  2. Verify the file at ~/.config/gcloud/application_default_credentials.json is not corrupted or a service-account key (which has a different shape)
  3. If ADC is not available, switch the Vertex AI auth method to an API-key-based setup or export proper service account credentials
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/client/vertexai.rs:511 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09). Data as JSON: /api/errors/bab6f7b9d8e03839. Report an issue: GitHub.

Appendix: source

Thrown at src/client/vertexai.rs:511

        .as_ref()
        .map(PathBuf::from)
        .or_else(default_adc_file)
        .ok_or_else(|| anyhow!("No application_default_credentials.json"))?;
    let data = tokio::fs::read_to_string(adc_file).await?;
    let data: Value = serde_json::from_str(&data)?;
    if let (Some(client_id), Some(client_secret), Some(refresh_token)) = (
        data["client_id"].as_str(),
        data["client_secret"].as_str(),
        data["refresh_token"].as_str(),
    ) {
        Ok(json!({
            "client_id": client_id,
            "client_secret": client_secret,
            "refresh_token": refresh_token,
            "grant_type": "refresh_token",
        }))
    } else {
        bail!("Invalid application_default_credentials.json")
    }
}

#[cfg(not(windows))]
fn default_adc_file() -> Option<PathBuf> {
    let mut path = dirs::home_dir()?;
    path.push(".config");
    path.push("gcloud");
    path.push("application_default_credentials.json");
    Some(path)
}

#[cfg(windows)]
fn default_adc_file() -> Option<PathBuf> {
    let mut path = dirs::config_dir()?;
    path.push("gcloud");
    path.push("application_default_credentials.json");
    Some(path)

View on GitHub (pinned to 82976d349a)