nautechsystems/nautilus_trader · error · anyhow::Error

Failed to create client builder: {e}

Error message

Failed to create client builder: {e}

What it means

DatabentoHistoricalClient::new builds the underlying databento::HistoricalClient via its builder. If the builder construction itself fails (before even building the client), the error is wrapped with this message, indicating a problem with builder initialization such as an invalid API key credential format.

Source

Thrown at crates/adapters/databento/src/historical.rs:110

    pub fn api_key(&self) -> &str {
        self.credential.api_key()
    }

    /// Creates a new [`DatabentoHistoricalClient`] instance.
    ///
    /// # Errors
    ///
    /// Returns an error if client creation or publisher loading fails.
    pub fn new(
        credential: Credential,
        publishers_filepath: PathBuf,
        clock: &'static AtomicTime,
        use_exchange_as_venue: bool,
    ) -> anyhow::Result<Self> {
        let client = databento::HistoricalClient::builder()
            .user_agent_extension(NAUTILUS_USER_AGENT.into())
            .key(credential.api_key())
            .map_err(|e| anyhow::anyhow!("Failed to create client builder: {e}"))?
            .build()
            .map_err(|e| anyhow::anyhow!("Failed to build client: {e}"))?;

        Self::from_client(
            credential,
            publishers_filepath,
            clock,
            use_exchange_as_venue,
            client,
        )
    }

    /// Creates a new [`DatabentoHistoricalClient`] instance with a custom API base URL.
    ///
    /// This is intended for tests, benchmarks, and controlled deployments that route
    /// Databento Historical API requests through a proxy.
    ///
    /// # Errors

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Validate the API key is non-empty and correctly formatted before constructing the client
  2. Inspect the wrapped source error for the underlying builder failure reason
  3. Re-create the credential from a valid DATABENTO_API_KEY
  4. Check databento crate version compatibility with the adapter

Example fix

// before
let client = DatabentoHistoricalClient::new(credential, publishers, clock, use_exchange_as_venue)?;
// after
assert!(!credential.api_key().is_empty(), "Databento API key must not be empty");
let client = DatabentoHistoricalClient::new(credential, publishers, clock, use_exchange_as_venue)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust
if credential.api_key().trim().is_empty() { bail!("key required"); }

Try / catch

// Rust
Err(e) => error!("init: {e:#}"),

Prevention

When it happens

Trigger: Calling DatabentoHistoricalClient::new with a credential whose api_key() cannot be applied to the builder (databento crate rejects the key format/empty key at builder stage).

Common situations: Malformed or empty Databento API key supplied as the credential; incompatible databento crate version producing builder errors; whitespace/encoding issues in the stored key.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/a9331539634dfdd8. Report an issue: GitHub.