{"record":{"id":"28c1c9769f86cfce","repo":"tiangolo/fastapi","slug":"x-token-header-invalid-28c1c9","errorCode":null,"errorMessage":"X-Token header invalid","messagePattern":"X-Token header invalid","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"docs_src/dependencies/tutorial006_py310.py","lineNumber":8,"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/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/docs_src/dependencies/tutorial006_py310.py#L1-L20","documentation":"Legacy-style variant of error 14: verify_token on GET /items/ raises 400 when X-Token != 'fake-super-secret-token'. Header injection uses x_token: str = Header() instead of Annotated. Behavior is identical.","triggerScenarios":"GET /items/ with a wrong/missing X-Token header.","commonSituations":"Stale client token; header stripped in transit; mismatch with another tutorial's token literal.","solutions":["Send X-Token: fake-super-secret-token.","Send X-Key: fake-super-secret-key as well (both are required).","Migrate to the Annotated variant for consistency with current docs."],"exampleFix":"// before\nGET /items/   X-Token: wrong\n// after\nGET /items/   X-Token: fake-super-secret-token","handlingStrategy":"validation","validationCode":"import httpx\nresp = httpx.get('http://localhost:8000/items/', headers={'X-Token': 'fake-super-secret-token', 'X-Key': 'fake-super-secret-key'})","typeGuard":"def is_valid_x_token(value: object) -> bool:\n    return isinstance(value, str) and value == 'fake-super-secret-token'","tryCatchPattern":null,"preventionTips":["Use one token/key pair across both file variants.","Prefer the Annotated variant for new code.","Centralize header construction."],"tags":["fastapi","authentication","dependency","header","dependencies-tutorial"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}