Files
openai-github-copilot/README.md
2025-07-13 15:18:03 +02:00

6.6 KiB

Why

Tip

GitHub Copilot Pro is free to use for verified students, teachers, and maintainers of popular open source projects.

Other options include limited experience of Copilot without a paid plan, or individual Copilot plan.

What

GitHub Copilot provides access to the latest generative models from OpenAI, Anthropic and Google.

Is is available through selected IDEs.

The openai-github-copilot project enables its use across a broader range of tools. It provides a general OpenAI-compatible API that can be deployed at no cost.
(However, a GitHub Copilot subscription is still required.)

Serverless?

Although it runs in the cloud, it does not require server maintenance. It can be easily deployed to Cloudflare for free (with generous limits suitable for personal use).

Tip

Running the proxy endpoint locally is also an option!

How to start

First, you need to create an account on Cloudflare.

The simplest way to deploy is by manually pasting content of src/worker.mjs into https://workers.cloudflare.com/playground (see there Deploy button).

Caution

This is a bit simplified version of the code, that does not implement token caching, and lacks a "/token" page.
To deploy full-featured version, please refer to the section below.

Advanced instructions

Button-deploy and CI are only supported on Github

Tip

If your account is new and you haven't created any workers yet, some of the links mentioned below might be inaccessible. Therefore, it's recommended to create at least a "Hello World" Worker: Deploy "Hello World" script.
You can name it "copilot".

Deploy to Cloudflare Workers

After clicking this button, you'll be guided through the process of forking the repository first, which is necessary for continuous integration (CI).

Warning

The initial deployment will fail, because it requires KV namespace, which does not exist yet.

Navigate to Workers & Pages / KV and create a namespace with "copilot-KV" name. Next, copy its ID, and modify the wrangler.toml file in your forked repository, replacing the existing id with your copied value.

Once you push these changes, the CI will automatically deploy the repo to Cloudflare Workers, this time without any issues.

Manual deployment

Instead of using the "button-deploy", you can also manage the project locally using the Cloudflare CLI:

  • Create a KV namespace: wrangler kv:namespace create KV
    (and update id value in your wrangler.toml file).
  • Serve locally: wrangler dev
  • Deploy to Cloudlare Workers: wrangler deploy

How to use

If you open your newly-deployed site in a browser, you will only see a 404 Not Found message. This is expected, as the API is not designed for direct browser access.
To utilize it, you should enter your API address and your Github Copilot access token into the corresponding fields in your software settings.

Note

Not all software tools allow overriding the OpenAI endpoint, but many do (however these settings can sometimes be deeply hidden).

API base / address / URL / ...

Typically, you should specify the API base in this format:
https://copilot.YOURSUBDOMAIN.workers.dev/v1

However, some software may expect it without the /v1 ending:
https://copilot.YOURSUBDOMAIN.workers.dev

The relevant field may be labeled as "OpenAI proxy". You might need to look under "Advanced settings" or similar sections. Alternatively, it could be in some config file (check the relevant documentation for details).

For some command-line tools, you may need to set an environment variable, e.g.:

OPENAI_BASE_URL="https://copilot.YOURSUBDOMAIN.workers.dev/v1"

..or:

OPENAI_API_BASE="https://copilot.YOURSUBDOMAIN.workers.dev/v1"

API key

First you need to obtain a Copilot-enabled Github access token (which should start either with ghu_ or gho_). Once deployed, this project provides a "/token" web page that assists in generating such a token.
For alternative methods, please refer to the scripts.

Input this token into the "OpenAI API key" field in your software settings. Alternatively, it might be located in some config file (check the relevant documentation for details).

For some command-line tools, you may need to set an environment variable, e.g.:

OPENAI_API_KEY=ghu_...

Models

The list of available models can be accessed through the standard /v1/models endpoint and may vary depending on the provided API key. Some models may need to be activated in the settings.

Examples: gpt-4.1, o4-mini, claude-3.7-sonnet-thought, gemini-2.5-pro.

Tech notes

Copilot provides following endpoints:

  • /v1/chat/completions
    • tools and other related properties are ignored.
    • Output is post-processed in order to remove differences from OpenAI's.
  • /v1/embeddings
    • input: supports array of strings only
    • encoding_format, dimensions: ignored.
    • Output is not altered in any way, and has some minor differences from OpenAI's:
      • no object property ("object": "embedding")
      • no model property ("model": "text-embedding-3-small")
  • /token: serves a Web page that allows you to obtain a Github Copilot access token.