Skip to content

Add upstream Responses API service client #4

@HXYerror

Description

@HXYerror

Part of #1. Depends on #2.

Goal

Add a service-layer client that POSTs to `${copilotBaseUrl(state)}/responses` with the correct VS Code spoof headers, mirroring the existing `create-chat-completions.ts`.

Current state

`src/services/copilot/` has only three call sites:

  • `create-chat-completions.ts:31` → `/chat/completions`
  • `create-embeddings.ts:8` → `/embeddings`
  • `get-models.ts:6` → `/models`

No code anywhere POSTs to a URL containing `responses`.

Tasks

  • Add `src/services/copilot/create-responses.ts` exporting `createResponses(payload, opts)`
  • Reuse `copilotBaseUrl(state)` and `copilotHeaders(state)` from `src/lib/api-config.ts`
  • Add the `X-Initiator` heuristic from `create-chat-completions.ts:21–29` adapted for the Responses input shape (`agent` if any input item has `role: 'assistant'` or `type: 'function_call_output'`, else `user`)
  • Add `Copilot-Vision-Request: true` when any `input_image` exists (separate sub-issue tracks this — leave a TODO)
  • Surface streaming via `fetch-event-stream` (same library used elsewhere)
  • Define TypeScript types for: `ResponsesRequest`, `ResponsesResponse`, `OutputItem` (union of `reasoning`, `message`, `function_call`, `function_call_output`), `ResponseStreamEvent` (union of all `response.*.delta` and `response.completed` etc.)

Acceptance criteria

  • Calling the service against a real Copilot token returns a 200 for `gpt-5` non-streaming, with `output[]` array shape
  • Streaming returns SSE chunks with `response.output_text.delta` events
  • Headers passed upstream match VS Code's wire format (verifiable with `--verbose`)

File pointers

  • `src/services/copilot/create-chat-completions.ts` (reference)
  • `src/lib/api-config.ts:16–19` (`copilotBaseUrl`)
  • `src/services/copilot/create-chat-completions.ts:21–29` (X-Initiator heuristic)

Reference impl

litellm: `litellm/llms/github_copilot/responses/transformation.py` (`GithubCopilotResponsesAPIConfig`)

Metadata

Metadata

Assignees

No one assigned

    Labels

    responses-apiOpenAI /v1/responses API support

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions