{"record":{"id":"dc99e22d8ca4a237","repo":"Aider-AI/aider","slug":"response-missing-token-field","errorCode":null,"errorMessage":"Response missing 'token' field","messagePattern":"Response missing 'token' field","errorType":"exception","errorClass":"GitHubCopilotTokenError","httpStatus":null,"severity":"error","filePath":"aider/models.py","lineNumber":981,"sourceCode":"            }\n\n            url = \"https://api.github.com/copilot_internal/v2/token\"\n            res = requests.get(url, headers=headers)\n            if res.status_code != 200:\n                safe_headers = {k: v for k, v in headers.items() if k != \"Authorization\"}\n                token_preview = github_token[:5] + \"...\" if len(github_token) >= 5 else github_token\n                safe_headers[\"Authorization\"] = f\"Bearer {token_preview}\"\n                raise GitHubCopilotTokenError(\n                    f\"GitHub Copilot API request failed (Status: {res.status_code})\\n\"\n                    f\"URL: {url}\\n\"\n                    f\"Headers: {json.dumps(safe_headers, indent=2)}\\n\"\n                    f\"JSON: {res.text}\"\n                )\n\n            response_data = res.json()\n            token = response_data.get(\"token\")\n            if not token:\n                raise GitHubCopilotTokenError(\"Response missing 'token' field\")\n\n            os.environ[openai_api_key] = token\n\n    def send_completion(self, messages, functions, stream, temperature=None):\n        if os.environ.get(\"AIDER_SANITY_CHECK_TURNS\"):\n            sanity_check_messages(messages)\n\n        if self.is_deepseek_r1():\n            messages = ensure_alternating_roles(messages)\n\n        kwargs = dict(\n            model=self.name,\n            stream=stream,\n        )\n\n        if self.use_temperature is not False:\n            if temperature is None:\n                if isinstance(self.use_temperature, bool):","sourceCodeStart":963,"sourceCodeEnd":999,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/models.py#L963-L999","documentation":"The Copilot token endpoint responded 200 but its JSON body lacked a usable 'token' field (response_data.get('token') returned None/empty). aider raises GitHubCopilotTokenError('Response missing 'token' field'). It indicates an unexpected but successful response payload — the endpoint contract changed or returned an error object with 200 — rather than a credential problem.","triggerScenarios":"GitHub changing/reshaping the undocumented copilot_internal/v2/token response schema, or a proxy/interceptor returning a 200 JSON body without 'token'. Only occurs after a 200 status passed the status check, so auth already worked.","commonSituations":"GitHub-side API contract drift breaking older aider versions months after release; corporate TLS-inspecting proxies rewriting responses; extremely rare relative to 401/403 errors.","solutions":["Update aider to the latest release (pip install --upgrade aider-chat) — schema drift is patched upstream quickly.","Retry once; a transient/garbled response (proxy interference) can produce a body without 'token'.","If behind a corporate proxy, bypass it for api.github.com and retry.","Report upstream at the aider repo if the newest version still fails — include the (redacted) response shape."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = model.send_completion(messages, None, False)\nexcept Exception as e:\n    if \"Response missing 'token' field\" in str(e):\n        # schema drift or transient body: upgrade aider, retry once\n        raise SystemExit(\"Copilot token response malformed — update aider-chat and retry.\")\n    raise","preventionTips":["Keep aider-chat updated when using GitHub Copilot models — the internal endpoint schema is undocumented and drifts.","Distinguish this from auth errors: 200 already returned, so do not churn credentials."],"tags":["github-copilot","api-contract","parsing","version-drift","aider"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}