{"record":{"id":"ac852056c10a30e2","repo":"VectifyAI/PageIndex","slug":"chatgpt-api-key-is-deprecated-set-openai-api-key","errorCode":null,"errorMessage":"CHATGPT_API_KEY is deprecated — set OPENAI_API_KEY instead.","messagePattern":"CHATGPT_API_KEY is deprecated — set OPENAI_API_KEY instead\\.","errorType":"console","errorClass":"FutureWarning","httpStatus":null,"severity":"warning","filePath":"pageindex/utils.py","lineNumber":64,"sourceCode":"        pass  # best-effort: a failed repair leaves litellm's own error\n\n\ndef _mute_litellm_bridge_usage_warning() -> None:\n    \"\"\"litellm's chat→Responses bridge (e.g. OpenAI gpt-5.4+ with function\n    tools) logs a chat-shaped usage dict inside a ResponseAPIUsage field\n    (litellm_logging._get_assembled_streaming_response, 1.97–1.98), and\n    pydantic reports it on every streamed turn. Hide exactly that message;\n    every other warning still surfaces.\"\"\"\n    import warnings\n    warnings.filterwarnings(\n        \"ignore\",\n        message=r\"Pydantic serializer warnings:\\s+\"\n                r\"(PydanticSerializationUnexpectedValue\\()?Expected `ResponseAPIUsage`\")\n\n# Backward compatibility: support CHATGPT_API_KEY as alias for OPENAI_API_KEY\nif not os.getenv(\"OPENAI_API_KEY\") and os.getenv(\"CHATGPT_API_KEY\"):\n    import warnings\n    warnings.warn(\"CHATGPT_API_KEY is deprecated — set OPENAI_API_KEY \"\n                  \"instead.\", FutureWarning)\n    os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"CHATGPT_API_KEY\")\n\ndef count_tokens(text, model=None):\n    if not text:\n        return 0\n    import litellm\n    return litellm.token_counter(model=model, text=text)\n\n\ndef _strip_prefix(s, prefix):\n    if s.startswith(prefix):\n        return s[len(prefix):]\n    return s\n\n\ndef run_off_loop(func, *args):\n    \"\"\"Run func now, or on a worker thread when this thread already runs an","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/VectifyAI/PageIndex/blob/afb5e119766630af6014b04fe8b53357527bc05e/pageindex/utils.py#L46-L82","documentation":"Module-level FutureWarning: if OPENAI_API_KEY is unset but the legacy CHATGPT_API_KEY is set, the latter is copied into OPENAI_API_KEY so requests still authenticate. It exists for backward compatibility with older ChatGPT-key deployments.","triggerScenarios":"Importing pageindex.utils in an environment that only defines CHATGPT_API_KEY (no OPENAI_API_KEY) — commonly a leftover from older scripts or CI secrets named the old way.","commonSituations":"CI/CD secrets or .env files created before the rename; shared containers where the old var leaks in; team conventions stuck on the legacy name.","solutions":["Rename the env var: export OPENAI_API_KEY=<same value> and remove CHATGPT_API_KEY from .env/CI secrets","Reload the shell/session so the old var is gone","Filter FutureWarning only temporarily if you cannot change the environment yet"],"exampleFix":"# before (.env)\nCHATGPT_API_KEY=sk-...\n# after (.env)\nOPENAI_API_KEY=sk-...","handlingStrategy":"validation","validationCode":"import os\nif not os.getenv('OPENAI_API_KEY') and os.getenv('CHATGPT_API_KEY'):\n    os.environ['OPENAI_API_KEY'] = os.environ.pop('CHATGPT_API_KEY')\n# import pageindex afterwards","typeGuard":null,"tryCatchPattern":"import warnings\nwith warnings.catch_warnings():\n    warnings.simplefilter('ignore', FutureWarning)\n    import pageindex  # legacy env still works, warning silenced","preventionTips":["Use OPENAI_API_KEY everywhere; delete CHATGPT_API_KEY from CI secrets and .env files","Audit container images and shells for stale exported variables","Fail CI on FutureWarnings to catch legacy env usage"],"tags":["env-var","api-key","deprecation","openai"],"backgroundTag":"renamed-env-var","analyzedSha":"afb5e119766630af6014b04fe8b53357527bc05e","analyzedAt":"2026-08-27T11:20:48.519Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}