Skip to content

OpenAI-compatible REST API server powered by GitHub Copilot SDK

License

Notifications You must be signed in to change notification settings

Houloude9IOfficial/CopAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CopAPI

Disclaimer

This repository was created quickly using AI for personal testing purposes. It will most likely not receive updates or maintenance.

DO NOT USE FOR COMMERCIAL OR PRODUCTION PURPOSES

The GitHub Copilot CLI has full filesystem access to the server directory. This means the AI can read, modify, or delete any files on the system. This is a significant security risk. Example of what the AI can do:

User: "read the files list"
AI: *reads and returns contents of all files in the directory*

Use this project at your own risk and only in isolated, non-sensitive environments.


An OpenAI-compatible REST API server powered by the GitHub Copilot SDK. Expose GitHub Copilot's capabilities through a standard OpenAI API interface, enabling seamless integration with existing tools and applications.

Features

  • Full OpenAI API compatibility (/v1/chat/completions, /v1/completions, /v1/models)
  • Streaming and non-streaming responses
  • Multiple model support (GPT-4o, Claude, O1, Gemini, and more)
  • Optional API key authentication
  • CORS support with configurable origins
  • Health check endpoint
  • Configurable timeouts

Prerequisites

  • Node.js >= 18.0.0
  • GitHub Copilot subscription
  • GitHub Copilot CLI

Installation

1. Install GitHub Copilot CLI

npm install -g @github/copilot

2. Authenticate with GitHub Copilot

github-copilot-cli auth

Follow the prompts to authenticate with your GitHub account. Make sure your account has an active GitHub Copilot subscription.

3. Clone and Install CopAPI

git clone https://github.com/Houloude9IOfficial/CopAPI.git
cd CopAPI
npm install

4. Configure Environment

cp .env.example .env

Edit .env with your preferred settings.

Configuration

Variable Description Default
PORT Server port 3000
DEFAULT_MODEL Default model when not specified gpt-4o
API_KEY API key for authentication (leave empty to disable) -
LOG_LEVEL Logging level (debug, info, warn, error) info
REQUEST_TIMEOUT Request timeout in milliseconds 300000
CORS_ORIGIN Allowed origins (* for all, or comma-separated URLs) *
CORS_CREDENTIALS Allow credentials in CORS requests false
COPILOT_CLI_PATH Custom path to Copilot CLI (optional) -
COPILOT_CLI_URL URL of existing CLI server (optional) -

Usage

Start the Server

npm start

Development Mode (with auto-reload)

npm run dev

API Reference

List Models

GET /v1/models

Get Model Details

GET /v1/models/:model

Chat Completions

POST /v1/chat/completions
Content-Type: application/json

{
  "model": "gpt-4o",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ],
  "stream": false
}

Text Completions

POST /v1/completions
Content-Type: application/json

{
  "model": "gpt-4o",
  "prompt": "Write a poem about coding",
  "stream": false
}

Health Check

GET /health

Supported Models

Model Description
gpt-4o GPT-4o (default)
gpt-4o-mini GPT-4o Mini
gpt-4 GPT-4
gpt-4-turbo GPT-4 Turbo
gpt-3.5-turbo GPT-3.5 Turbo
gpt-5 GPT-5
claude-sonnet-4.5 Claude Sonnet 4.5
claude-sonnet-4 Claude Sonnet 4
o1 O1
o1-mini O1 Mini
o1-pro O1 Pro
o3-mini O3 Mini
gemini-2.0-flash-001 Gemini 2.0 Flash

CORS (Cross-Origin Resource Sharing)

CORS is enabled by default to allow requests from any origin. Configure it using environment variables:

Allow All Origins (Default)

CORS_ORIGIN=*

Allow Specific Origins

CORS_ORIGIN=https://example.com,https://app.example.com

Enable Credentials

If your client needs to send cookies or authentication headers:

CORS_ORIGIN=https://example.com
CORS_CREDENTIALS=true

Note: When CORS_CREDENTIALS=true, you cannot use CORS_ORIGIN=*. You must specify explicit origins.

Authentication

If API_KEY is configured, include it in all requests:

Authorization: Bearer your-api-key-here

Example Usage

cURL

curl http://localhost:3000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:3000/v1",
    api_key="your-api-key"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)

JavaScript

const response = await fetch("http://localhost:3000/v1/chat/completions", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    model: "gpt-4o",
    messages: [{ role: "user", content: "Hello!" }]
  })
});

const data = await response.json();
console.log(data.choices[0].message.content);

Troubleshooting

"Copilot CLI not found"

Ensure the GitHub Copilot CLI is installed globally and accessible in your PATH:

npm install -g @github/copilot

"Authentication failed"

Re-authenticate with the Copilot CLI:

github-copilot-cli auth

"Timeout errors"

Increase the REQUEST_TIMEOUT value in your .env file.

License

MIT

About

OpenAI-compatible REST API server powered by GitHub Copilot SDK

Topics

Resources

License

Stars

Watchers

Forks