{"record":{"id":"2117ffe27e57fd35","repo":"BerriAI/litellm","slug":"private-key-file-not-found-file-path","errorCode":null,"errorMessage":"Private key file not found: {file_path}","messagePattern":"Private key file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"critical","filePath":"litellm/llms/oci/common_utils.py","lineNumber":133,"sourceCode":"\ndef load_private_key_from_str(key_str: str) -> Any:\n    _require_cryptography()\n    key: Final = serialization.load_pem_private_key(\n        key_str.encode(\"utf-8\"),\n        password=None,\n    )\n    if not isinstance(key, rsa.RSAPrivateKey):\n        raise TypeError(\"The provided private key is not an RSA key, which is required for OCI signing.\")\n    return key\n\n\ndef load_private_key_from_file(file_path: str) -> Any:\n    \"\"\"Loads a private key from a file path.\"\"\"\n    try:\n        with open(file_path, \"r\", encoding=\"utf-8\") as f:\n            key_str: Final = f.read().strip()\n    except FileNotFoundError:\n        raise FileNotFoundError(f\"Private key file not found: {file_path}\")\n    except OSError as e:\n        raise OSError(f\"Failed to read private key file '{file_path}': {e}\") from e\n\n    if not key_str:\n        raise ValueError(f\"Private key file is empty: {file_path}\")\n\n    return load_private_key_from_str(key_str)\n\n\n# ---------------------------------------------------------------------------\n# Env-var credential resolution\n# ---------------------------------------------------------------------------\n\n_OCI_REGION_ENV: Final = \"OCI_REGION\"\n_OCI_USER_ENV: Final = \"OCI_USER\"\n_OCI_FINGERPRINT_ENV: Final = \"OCI_FINGERPRINT\"\n_OCI_TENANCY_ENV: Final = \"OCI_TENANCY\"\n_OCI_KEY_FILE_ENV: Final = \"OCI_KEY_FILE\"","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/oci/common_utils.py#L115-L151","documentation":"load_private_key_from_file re-raises FileNotFoundError with a clearer message when the path given via oci_key_file / OCI_KEY_FILE does not exist. It is a configuration error: the signing path resolved a key path, but the filesystem has no file there.","triggerScenarios":"OCI_KEY_FILE set to a relative path that resolves differently in the deployed cwd; Docker container missing the mounted key volume; typo in the path; key file present locally but absent in CI/prod; '~' not expanded.","commonSituations":"Works-on-my-machine path bugs: '~/.oci/oci_api_key.pem' left unexpanded by a non-shell process, paths from an .env file not mounted into the container, volume mount path mismatch in Kubernetes secrets, or a typo'd filename.","solutions":["Check the exact path: use an absolute path for oci_key_file / OCI_KEY_FILE.","In containers, confirm the secret/volume is mounted at that path (kubectl exec ls).","Expand user paths programmatically: os.path.expanduser() before passing.","Alternatively embed the PEM content directly via oci_key to remove the filesystem dependency."],"exampleFix":"# before\nos.environ[\"OCI_KEY_FILE\"] = \"~/.oci/oci_api_key.pem\"  # literal ~ not expanded\n\n# after\nimport os\nos.environ[\"OCI_KEY_FILE\"] = os.path.expanduser(\"~/.oci/oci_api_key.pem\")\nassert os.path.exists(os.environ[\"OCI_KEY_FILE\"])","handlingStrategy":"validation","validationCode":"import os\nkey_path = os.path.expanduser(os.environ.get(\"OCI_KEY_FILE\", \"\"))\nassert key_path and os.path.isfile(key_path), f\"OCI key file missing: {key_path!r}\"","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=\"oci/...\", messages=m)\nexcept FileNotFoundError as e:\n    if \"Private key file\" in str(e):\n        raise ConfigError(f\"mount/copy the key to {path_from_error}\") from e\n    raise","preventionTips":["Always use absolute, expanduser'd paths for OCI_KEY_FILE.","Assert file existence at startup in every environment.","Prefer inline OCI_KEY from a secret manager to avoid filesystem coupling."],"tags":["oci","authentication","file-not-found","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}