{"record":{"id":"10999fcbb3f8049e","repo":"nautechsystems/nautilus_trader","slug":"api-key-must-be-provided-or-set-in-the-tardis-api","errorCode":null,"errorMessage":"API key must be provided or set in the 'TARDIS_API_KEY' environment variable","messagePattern":"API key must be provided or set in the 'TARDIS_API_KEY' environment variable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/tardis/src/http/client.rs","lineNumber":92,"sourceCode":"\nimpl TardisHttpClient {\n    /// Creates a new [`TardisHttpClient`] instance.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if no API key is provided (argument or `TARDIS_API_KEY` env var),\n    /// or if the HTTP client cannot be built.\n    pub fn new(\n        api_key: Option<&str>,\n        base_url: Option<&str>,\n        timeout_secs: Option<u64>,\n        normalize_symbols: bool,\n        proxy_url: Option<String>,\n    ) -> anyhow::Result<Self> {\n        let credential = Credential::resolve(api_key.map(ToString::to_string));\n\n        if credential.is_none() {\n            anyhow::bail!(\n                \"API key must be provided or set in the 'TARDIS_API_KEY' environment variable\"\n            );\n        }\n\n        let base_url =\n            base_url.map_or_else(|| TARDIS_HTTP_BASE_URL.to_string(), ToString::to_string);\n\n        let mut headers = HashMap::new();\n        headers.insert(USER_AGENT.to_string(), NAUTILUS_USER_AGENT.to_string());\n\n        if let Some(ref cred) = credential {\n            headers.insert(\n                \"Authorization\".to_string(),\n                format!(\"Bearer {}\", cred.api_key()),\n            );\n        }\n\n        let keyed_quotas = vec![(TARDIS_REST_RATE_KEY.to_string(), *TARDIS_REST_QUOTA)];","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/tardis/src/http/client.rs#L74-L110","documentation":"The Tardis HTTP client requires an API key for authentication (Tardis API is key-gated). Credential::resolve checks the explicit `api_key` argument and then the TARDIS_API_KEY environment variable; if neither yields a credential, the client refuses to construct.","triggerScenarios":"Calling the Tardis HTTP client constructor (new) with None/empty api_key while the TARDIS_API_KEY environment variable is unset in the process environment.","commonSituations":"Forgot to export TARDIS_API_KEY in the shell or container; key set in a different environment (IDE vs terminal vs systemd); key passed with surrounding whitespace or as an empty string; running in CI where the secret wasn't injected.","solutions":["Set the environment variable: export TARDIS_API_KEY=\"your-key\"","Pass the key explicitly to the constructor: api_key = Some(\"your-key\")","In CI/deployment, inject the secret into the environment (e.g. GitHub Actions secrets, docker -e)","Check for typos in the env var name and that the process actually inherits it (printenv TARDIS_API_KEY)"],"exampleFix":"// before\nlet client = TardisHttpClient::new(None, None, None, None)?;  // no key anywhere\n// after\nlet client = TardisHttpClient::new(Some(\"td-xxxx\"), None, None, None)?;\n// or: export TARDIS_API_KEY=\"td-xxxx\" then TardisHttpClient::new(None, ...)","handlingStrategy":"validation","validationCode":"fn ensure_tardis_key(api_key: Option<&str>) -> Result<(), String> {\n    let resolved = api_key\n        .map(str::trim)\n        .filter(|k| !k.is_empty())\n        .map(String::from)\n        .or_else(|| std::env::var(\"TARDIS_API_KEY\").ok());\n    match resolved {\n        Some(_) => Ok(()),\n        None => Err(\"Set TARDIS_API_KEY or pass api_key\".into()),\n    }\n}","typeGuard":null,"tryCatchPattern":"let client = TardisHttpClient::new(api_key, None, None, None)\n    .map_err(|e| {\n        if e.to_string().contains(\"API key must be provided\") {\n            anyhow::anyhow!(\"TARDIS_API_KEY missing: export it or pass api_key explicitly\")\n        } else { e }\n    })?;","preventionTips":["Export TARDIS_API_KEY in shell profiles and container images","Verify with `printenv TARDIS_API_KEY` in the exact runtime environment","Inject secrets in CI rather than relying on local env"],"tags":["api-key","authentication","env-var","tardis"],"backgroundTag":"missing-api-key","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}