Aider-AI/aider · error · GitHubCopilotTokenError
Response missing 'token' field
Error message
Response missing 'token' field
What it means
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.
Source
Thrown at aider/models.py:981
}
url = "https://api.github.com/copilot_internal/v2/token"
res = requests.get(url, headers=headers)
if res.status_code != 200:
safe_headers = {k: v for k, v in headers.items() if k != "Authorization"}
token_preview = github_token[:5] + "..." if len(github_token) >= 5 else github_token
safe_headers["Authorization"] = f"Bearer {token_preview}"
raise GitHubCopilotTokenError(
f"GitHub Copilot API request failed (Status: {res.status_code})\n"
f"URL: {url}\n"
f"Headers: {json.dumps(safe_headers, indent=2)}\n"
f"JSON: {res.text}"
)
response_data = res.json()
token = response_data.get("token")
if not token:
raise GitHubCopilotTokenError("Response missing 'token' field")
os.environ[openai_api_key] = token
def send_completion(self, messages, functions, stream, temperature=None):
if os.environ.get("AIDER_SANITY_CHECK_TURNS"):
sanity_check_messages(messages)
if self.is_deepseek_r1():
messages = ensure_alternating_roles(messages)
kwargs = dict(
model=self.name,
stream=stream,
)
if self.use_temperature is not False:
if temperature is None:
if isinstance(self.use_temperature, bool):View on GitHub (pinned to 5dc9490bb3)
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.
Defensive patterns
Strategy: retry
Try / catch
try:
out = model.send_completion(messages, None, False)
except Exception as e:
if "Response missing 'token' field" in str(e):
# schema drift or transient body: upgrade aider, retry once
raise SystemExit("Copilot token response malformed — update aider-chat and retry.")
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Bad/missing filename. The filename must be alone on the line
- Expected `=======`
- Expected `>>>>>>> REPLACE` or `=======`
- {processed}\n^^^ {err}
- Invalid patch line found in update section: {line}
AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15).
Data as JSON: /api/errors/dc99e22d8ca4a237.
Report an issue: GitHub.