nautechsystems/nautilus_trader · error

incomplete Lighter credentials: set {api_key_var}, {api_secr

Error message

incomplete Lighter credentials: set {api_key_var}, {api_secret_var}, and {account_index_var}

What it means

Lighter credentials are resolved from three sources (api key index, api secret, account index). Resolution succeeds only when all three are present or all three are absent; a partial set (some set, some missing) is ambiguous and rejected, with the message naming the exact env vars that must be set.

Source

Thrown at crates/adapters/lighter/src/common/credential.rs:277

    out
}

fn credential_from_resolved_values(
    api_key_index: Option<u8>,
    account_index: Option<u64>,
    api_secret: Option<String>,
    api_key_var: &str,
    api_secret_var: &str,
    account_index_var: &str,
) -> anyhow::Result<Option<Credential>> {
    match (api_key_index, account_index, api_secret) {
        (Some(api_key_index), Some(account_index), Some(api_secret)) => Ok(Some(Credential::new(
            api_key_index,
            api_secret,
            account_index,
        )?)),
        (None, None, None) => Ok(None),
        _ => anyhow::bail!(
            "incomplete Lighter credentials: set {api_key_var}, {api_secret_var}, and {account_index_var}"
        ),
    }
}

fn resolve_api_key_index(value: Option<u8>, env_var: &str) -> anyhow::Result<Option<u8>> {
    match value {
        Some(value) => ensure_api_key_index(value).map(Some),
        None => get_or_env_var_opt(None::<String>, env_var)
            .filter(|s| !s.trim().is_empty())
            .map(|s| parse_api_key_index(&s, env_var))
            .transpose(),
    }
}

fn resolve_account_index(value: Option<u64>, env_var: &str) -> anyhow::Result<Option<u64>> {
    match value {
        Some(value) => Ok(Some(value)),

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set all three env vars: the api key index var, api secret var, and account index var named in the error message (e.g. LIGHTER_API_KEY_INDEX, LIGHTER_API_SECRET, LIGHTER_ACCOUNT_INDEX).
  2. Alternatively unset all three if unauthenticated/no-credential operation is intended.
  3. Audit your deployment environment/dotenv file so the credential set is complete and consistent.
  4. Add a startup validation step that checks the three vars together before launching the adapter.

Example fix

// before
export LIGHTER_API_KEY_INDEX=1
export LIGHTER_API_SECRET=...
# LIGHTER_ACCOUNT_INDEX missing
// after
export LIGHTER_API_KEY_INDEX=1
export LIGHTER_API_SECRET=...
export LIGHTER_ACCOUNT_INDEX=12345
Defensive patterns

Strategy: validation

Validate before calling

let key_idx = env::var("LIGHTER_API_KEY_INDEX").ok();
let secret = env::var("LIGHTER_API_SECRET").ok();
let acct = env::var("LIGHTER_ACCOUNT_INDEX").ok();
let set = [key_idx.is_some(), secret.is_some(), acct.is_some()];
if set.iter().any(|&x| x) && !set.iter().all(|&x| x) {
    return Err("incomplete Lighter credentials: set all three vars or none".into());
}

Try / catch

match resolve_for_deployment() {
    Err(e) if e.to_string().contains("incomplete Lighter credentials") => {
        // fail startup with a clear operator message naming the missing vars
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling credential_from_resolved_values (via resolve_for_deployment) when exactly one or two of api_key_index/account_index/api_secret are provided — e.g. LIGHTER_API_KEY_INDEX and LIGHTER_API_SECRET set but LIGHTER_ACCOUNT_INDEX missing.

Common situations: Partial environment configuration during setup or migration; rotating credentials and clearing only one variable; provisioning systems injecting only part of the credential set; forgetting the account index, which is unique to Lighter.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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