{"id":"506fb6c7711b1170","repo":"tiangolo/fastapi","slug":"x-key-header-invalid-506fb6","errorCode":null,"errorMessage":"X-Key header invalid","messagePattern":"X-Key header invalid","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"docs_src/dependencies/tutorial006_py310.py","lineNumber":13,"sourceCode":"from fastapi import Depends, FastAPI, Header, HTTPException\n\napp = FastAPI()\n\n\nasync def verify_token(x_token: str = Header()):\n    if x_token != \"fake-super-secret-token\":\n        raise HTTPException(status_code=400, detail=\"X-Token header invalid\")\n\n\nasync def verify_key(x_key: str = Header()):\n    if x_key != \"fake-super-secret-key\":\n        raise HTTPException(status_code=400, detail=\"X-Key header invalid\")\n    return x_key\n\n\n@app.get(\"/items/\", dependencies=[Depends(verify_token), Depends(verify_key)])\nasync def read_items():\n    return [{\"item\": \"Foo\"}, {\"item\": \"Bar\"}]\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/tiangolo/fastapi/blob/42a41db11f6882807ac3c057b942178d53b97438/docs_src/dependencies/tutorial006_py310.py#L1-L20","documentation":"Non-Annotated variant of error 15: verify_key raises HTTP 400 when X-Key != \"fake-super-secret-key\". Same stacked-dependency guard as the Annotated version.","triggerScenarios":"GET /items/ with X-Token correct but X-Key missing/wrong.","commonSituations":"Client sets only the token header; one header dropped by infrastructure.","solutions":["Send X-Key: fake-super-secret-key alongside X-Token.","Use a shared headers dict for all calls.","Verify both dependencies pass."],"exampleFix":"# before\nheaders={\"X-Token\":\"fake-super-secret-token\"}\n# after\nheaders={\"X-Token\":\"fake-super-secret-token\",\"X-Key\":\"fake-super-secret-key\"}","handlingStrategy":"validation","validationCode":"headers = {\"X-Token\": \"fake-super-secret-token\", \"X-Key\": \"fake-super-secret-key\"}\nclient.get(\"/items/\", headers=headers)","typeGuard":"def has_both_headers(h: dict) -> bool:\n    return h.get(\"X-Token\") == \"fake-super-secret-token\" and h.get(\"X-Key\") == \"fake-super-secret-key\"","tryCatchPattern":null,"preventionTips":["Never send only one of the two required headers.","Use a shared headers dict.","Confirm both headers survive the transport layer."],"tags":["fastapi","authentication","dependencies","http-headers"],"analyzedSha":"42a41db11f6882807ac3c057b942178d53b97438","analyzedAt":"2026-08-04T19:23:32.007Z","schemaVersion":2}