Skip to content

500 error when adding context using claude code with Claude 4 models hosted by GitHub Copilot #62

@anson627

Description

@anson627

ERROR Error occurred: Failed to create chat completions 12:25:26 PM

at I (/opt/homebrew/lib/node_modules/copilot-api/dist/main.js:2:8395)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async _e (/opt/homebrew/lib/node_modules/copilot-api/dist/main.js:8:3051)
at async /opt/homebrew/lib/node_modules/copilot-api/dist/main.js:8:3757
at async dispatch (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async cors2 (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/cors/index.js:84:5)
at async dispatch (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async logger2 (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/logger/index.js:38:5)
at async dispatch (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async /opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/hono-base.js:201:25

ERROR HTTP error: { error: 12:25:26 PM
{ message:
'messages.8: tool_use ids were found without tool_result blocks immediately after: toolu_016F4YKDQwPpE5Vxh9GZoatt. Each tool_use block must have a corresponding tool_result block in the next message.',
code: 'invalid_request_body' } }

TypeError: Body is unusable: Body has already been read
at consumeBody (node:internal/deps/undici/undici:6197:15)
at _Response.text (node:internal/deps/undici/undici:6149:18)
at f (file:///opt/homebrew/lib/node_modules/copilot-api/dist/main.js:2:1937)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async file:///opt/homebrew/lib/node_modules/copilot-api/dist/main.js:8:3785
at async dispatch (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async cors2 (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/cors/index.js:84:5)
at async dispatch (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async logger2 (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/logger/index.js:38:5)
at async dispatch (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
--> POST /v1/messages?beta=true 500 718ms
<-- POST /v1/messages?beta=true

ERROR Failed to create chat completions Response { status: 400, 12:26:03 PM
statusText: 'Bad Request',
headers:
Headers { 'content-security-policy': "default-src 'none'; sandbox",
'content-type': 'text/plain; charset=utf-8',
'copilot-edits-session': '1752780363.cf0fae7fca7494f5776bb08d803bd2c30cf234b44272c29cdd8ee4d1a060840c',
'strict-transport-security': 'max-age=31536000',
'x-content-type-options': 'nosniff',
'x-request-id': '205acef1-65bc-41b9-993a-48f319f20557',
date: 'Thu, 17 Jul 2025 19:26:03 GMT',
'content-length': '261',
'x-github-backend': 'Kubernetes',
'x-github-request-id': 'DC36:310320:1B342D:21409A:68794E4B' },
body: ReadableStream { locked: false, state: 'readable', supportsBYOB: true },
bodyUsed: false,
ok: false,
redirected: false,
type: 'basic',
url: 'https://api.githubcopilot.com/chat/completions' }

ERROR Error occurred: Failed to create chat completions 12:26:03 PM

at I (/opt/homebrew/lib/node_modules/copilot-api/dist/main.js:2:8395)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async _e (/opt/homebrew/lib/node_modules/copilot-api/dist/main.js:8:3051)
at async /opt/homebrew/lib/node_modules/copilot-api/dist/main.js:8:3757
at async dispatch (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async cors2 (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/cors/index.js:84:5)
at async dispatch (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async logger2 (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/logger/index.js:38:5)
at async dispatch (/opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async /opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/hono-base.js:201:25

ERROR HTTP error: { error: 12:26:03 PM
{ message:
'messages.8: tool_use ids were found without tool_result blocks immediately after: toolu_016F4YKDQwPpE5Vxh9GZoatt. Each tool_use block must have a corresponding tool_result block in the next message.',
code: 'invalid_request_body' } }

TypeError: Body is unusable: Body has already been read
at consumeBody (node:internal/deps/undici/undici:6197:15)
at _Response.text (node:internal/deps/undici/undici:6149:18)
at f (file:///opt/homebrew/lib/node_modules/copilot-api/dist/main.js:2:1937)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async file:///opt/homebrew/lib/node_modules/copilot-api/dist/main.js:8:3785
at async dispatch (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async cors2 (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/cors/index.js:84:5)
at async dispatch (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
at async logger2 (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/middleware/logger/index.js:38:5)
at async dispatch (file:///opt/homebrew/lib/node_modules/copilot-api/node_modules/hono/dist/compose.js:22:17)
--> POST /v1/messages?beta=true 500 541ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions