GitHub Copilot

GitHub Copilot

자동 인증 처리가 포함된 GitHub Copilot Chat API를 지원해요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 GitHub Copilot Chat API는 GitHub의 AI 기반 코딩 어시스턴트 접근 제공
LiteLLM 라우트 github_copilot/
지원 엔드포인트 /chat/completions, /embeddings
API 참조 GitHub Copilot docs

인증 (Authentication)

GitHub Copilot은 OAuth device flow를 사용해요. 처음 사용 시 GitHub로 인증하라는 프롬프트가 표시돼요:

  1. LiteLLM이 device code와 verification URL을 표시
  2. URL을 방문해 코드를 입력해 인증
  3. 자격 증명은 추후 사용을 위해 로컬에 저장

LiteLLM Python SDK 사용법

Chat Completion

from litellm import completion

response = completion(
    model="github_copilot/gpt-5.2",
    messages=[
        {"role": "system", "content": "You are a helpful coding assistant"},
        {"role": "user", "content": "Write a Python function to calculate fibonacci numbers"}
    ]
)
print(response)

스트리밍:

from litellm import completion

stream = completion(
    model="github_copilot/gpt-5.2",
    messages=[{"role": "user", "content": "Explain async/await in Python"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

Responses

GPT Codex 모델의 경우 responses API만 지원돼요.

import litellm

response = await litellm.aresponses(
    model="github_copilot/gpt-5.1-codex",
    input="Write a Python hello world",
    max_output_tokens=500
)
print(response)

Embedding

import litellm

response = litellm.embedding(
    model="github_copilot/text-embedding-3-small",
    input=["good morning from litellm"]
)
print(response)

LiteLLM Proxy 사용법

config.yaml에 다음을 추가:

model_list:
  - model_name: github_copilot/gpt-5.2
    litellm_params:
      model: github_copilot/gpt-5.2
  - model_name: github_copilot/gpt-5.1-codex
    model_info:
      mode: responses
    litellm_params:
      model: github_copilot/gpt-5.1-codex
  - model_name: github_copilot/text-embedding-ada-002
    model_info:
      mode: embedding
    litellm_params:
      model: github_copilot/text-embedding-ada-002

LiteLLM Proxy 서버 시작:

litellm --config config.yaml
# RUNNING on http://0.0.0.0:4000

OpenAI SDK:

from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
    base_url="http://localhost:4000",  # Your proxy URL
    api_key="your-proxy-api-key"  # Your proxy API key
)

# Non-streaming response
response = client.chat.completions.create(
    model="github_copilot/gpt-5.2",
    messages=[{"role": "user", "content": "How do I optimize this SQL query?"}]
)
print(response.choices[0].message.content)

LiteLLM SDK:

import litellm

# Configure LiteLLM to use your proxy
response = litellm.completion(
    model="litellm_proxy/github_copilot/gpt-5.2",
    messages=[{"role": "user", "content": "Review this code for bugs"}],
    api_base="http://localhost:4000",
    api_key="your-proxy-api-key"
)
print(response.choices[0].message.content)

cURL:

curl http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-p...-key" \
  -d '{
    "model": "github_copilot/gpt-5.2",
    "messages": [{"role": "user", "content": "Explain this error message"}]
  }'

시작하기 (Getting Started)

  1. GitHub Copilot 접근 권한 확인 (유료 GitHub 구독 필요)
  2. 첫 LiteLLM 요청 실행 - 인증 프롬프트가 표시됨
  3. device flow 인증 과정 진행
  4. LiteLLM을 통해 GitHub Copilot 요청 시작

설정 (Configuration)

토큰 저장 위치를 커스터마이즈할 수 있어요:

# Optional: Custom token directory
export GITHUB_COPILOT_TOKEN_DIR="~/.config/litellm/github_copilot"

# Optional: Custom access token file name
export GITHUB_COPILOT_ACCESS_TOKEN_FILE="access-token"

# Optional: Custom API key file name
export GITHUB_COPILOT_API_KEY_FILE="api-key.json"

# Optional: Custom Copilot endpoints for authentication and usage
# (needed when using GitHub Enterprise subscriptions with custom endpoints or self-hosted GitHub servers)
export GITHUB_COPILOT_API_BASE="https://copilot-api.my-company.ghe.com"
export GITHUB_COPILOT_DEVICE_CODE_URL="https://my-company.ghe.com/login/device/code"
export GITHUB_COPILOT_ACCESS_TOKEN_URL="https://my-company.ghe.com/login/oauth/access_token"
export GITHUB_COPILOT_API_KEY_URL="https://my-company.ghe.com/api/v3/copilot_internal/v2/token"

추가 헤더를 설정할 수도 있어요:

extra_headers = {
    "editor-version": "vscode/1.85.1",  # Editor version
    "editor-plugin-version": "copilot/1.155.0",  # Plugin version
    "Copilot-Integration-Id": "vscode-chat",  # Integration ID
    "user-agent": "GithubCopilot/1.155.0"  # User agent
}

더 알아보기 (Learn more)