Documentation
¶
Overview ¶
Package githubcopilot routes requests to the GitHub Copilot API, billed against a GitHub Copilot subscription instead of a model vendor's API key.
The upstream is OpenAI-compatible but splits its models across endpoints: GPT-5 and later answer only on /responses, while Claude, Gemini, and older GPT models answer on /chat/completions. The provider learns each model's endpoints from GET /models and serves both APIs on every model, translating when the model lacks the endpoint the client called.
Index ¶
- Variables
- func New(cfg providers.ProviderConfig, opts providers.ProviderOptions) core.Provider
- type Provider
- func (p *Provider) ChatCompletion(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
- func (p *Provider) Embeddings(ctx context.Context, req *core.EmbeddingRequest) (*core.EmbeddingResponse, error)
- func (p *Provider) ListModels(ctx context.Context) (*core.ModelsResponse, error)
- func (p *Provider) Responses(ctx context.Context, req *core.ResponsesRequest) (*core.ResponsesResponse, error)
- func (p *Provider) StreamChatCompletion(ctx context.Context, req *core.ChatRequest) (io.ReadCloser, error)
- func (p *Provider) StreamResponses(ctx context.Context, req *core.ResponsesRequest) (io.ReadCloser, error)
Constants ¶
This section is empty.
Variables ¶
var Registration = providers.Registration{ Type: providerType, New: New, Discovery: providers.DiscoveryConfig{ DefaultBaseURL: defaultBaseURL, }, }
Registration provides factory registration for the GitHub Copilot provider. The "github-copilot" type derives GITHUB_COPILOT_API_KEY, GITHUB_COPILOT_BASE_URL, and GITHUB_COPILOT_MODELS by convention.
Functions ¶
func New ¶
func New(cfg providers.ProviderConfig, opts providers.ProviderOptions) core.Provider
New creates a new GitHub Copilot provider. The API key is a GitHub OAuth token for an account with Copilot access; it is sent as-is, with no exchange for a short-lived Copilot token.
Types ¶
type Provider ¶
type Provider struct {
*openai.ChatCompatible
// contains filtered or unexported fields
}
Provider implements the core.Provider interface for GitHub Copilot. Chat completions, embeddings, and passthrough go through the shared chat-centric adapter; ChatCompletion and Responses pick the upstream endpoint per model (see endpoints.go), and normalize.go smooths over Copilot's departures from the OpenAI wire format.
func (*Provider) ChatCompletion ¶
func (p *Provider) ChatCompletion(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
ChatCompletion sends the request to /chat/completions, or through the Responses API for a model Copilot serves only there.
func (*Provider) Embeddings ¶
func (p *Provider) Embeddings(ctx context.Context, req *core.EmbeddingRequest) (*core.EmbeddingResponse, error)
Embeddings sends the request to /embeddings. Copilot rejects a bare string input with a 400, so it is wrapped into the one-element list OpenAI treats it as, and the reply gets the list object type Copilot omits.
func (*Provider) ListModels ¶
ListModels returns the models the account may call. A model whose policy is "disabled" is listed by Copilot but rejected on use until the account (or its organization) enables it in the Copilot settings, so it is left out. The listing also refreshes the per-model endpoint routes.
func (*Provider) Responses ¶
func (p *Provider) Responses(ctx context.Context, req *core.ResponsesRequest) (*core.ResponsesResponse, error)
Responses forwards the request to /responses for a model Copilot serves there, and translates it to chat completions otherwise.
func (*Provider) StreamChatCompletion ¶
func (p *Provider) StreamChatCompletion(ctx context.Context, req *core.ChatRequest) (io.ReadCloser, error)
StreamChatCompletion is ChatCompletion for streaming requests.
func (*Provider) StreamResponses ¶
func (p *Provider) StreamResponses(ctx context.Context, req *core.ResponsesRequest) (io.ReadCloser, error)
StreamResponses is Responses for streaming requests.