nautechsystems/nautilus_trader · critical · anyhow::Error
API key is required
Error message
API key is required
What it means
DatabentoDataClientConfigBuilder::build validates required fields; the Databento API key is mandatory for authentication with the Databento gateway. If api_key was never set on the builder, build() fails with this error before any client is created.
Source
Thrown at crates/adapters/databento/src/factories.rs:226
self
}
/// Sets whether to timestamp bars on close.
#[must_use]
pub const fn bars_timestamp_on_close(mut self, timestamp_on_close: bool) -> Self {
self.bars_timestamp_on_close = timestamp_on_close;
self
}
/// Builds the [`DatabentoDataClientConfig`].
///
/// # Errors
///
/// Returns an error if required fields are missing.
pub fn build(self) -> anyhow::Result<DatabentoDataClientConfig> {
let api_key = self
.api_key
.ok_or_else(|| anyhow::anyhow!("API key is required"))?;
let publishers_filepath = self
.publishers_filepath
.ok_or_else(|| anyhow::anyhow!("Publishers filepath is required"))?;
Ok(DatabentoDataClientConfig::new(
api_key.into_inner(),
publishers_filepath,
self.use_exchange_as_venue,
self.bars_timestamp_on_close,
))
}
}
#[cfg(test)]
mod tests {
use nautilus_core::time::get_atomic_clock_realtime;
use rstest::rstest;
View on GitHub (pinned to 18893faf8b)
Solutions
- Set the DATABENTO_API_KEY environment variable with a valid key from your Databento account
- Call .api_key(...) explicitly on the builder before build()
- Verify the env var is present and non-empty in the runtime environment (CI, container, shell profile)
- Check config file loading so the api_key field is actually parsed and passed to the builder
Example fix
// before
let config = DatabentoDataClientConfig::builder().publishers_filepath(path).build()?;
// after
let key = std::env::var("DATABENTO_API_KEY")?;
let config = DatabentoDataClientConfig::builder().api_key(key).publishers_filepath(path).build()?; Defensive patterns
Strategy: validation
Validate before calling
// Rust
if std::env::var("DATABENTO_API_KEY").map_or(true, |k| k.trim().is_empty()) { bail!("key required"); } Try / catch
// Rust
Err(e) => error!("config: {e:#}"), Prevention
- Set env var everywhere
- Fail fast on empty
- Verify CI secrets
- Check config files
When it happens
Trigger: Constructing DatabentoDataClientConfig via its builder without calling .api_key(...) — e.g. an empty/unset DATABENTO_API_KEY env var feeding the builder, or a config file missing the key field.
Common situations: Missing or misspelled DATABENTO_API_KEY environment variable; empty env var read as None; config YAML/TOML without the api_key entry; running in CI where secrets are not injected.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- Publishers filepath is required
- Failed to build client: {e}
- Invalid config type for AxExecutionClientFactory. Expected A
- Invalid factory address for DEX {name} on chain {chain} for
- heartbeat_secs must be positive when set
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/db21129f7730f976.
Report an issue: GitHub.