Skip to main content

Server-to-server authentication

Use a short-lived installation access token when a service needs to make Copilot requests on behalf of an organization without a user's credentials. In GitHub Actions, use the built-in GITHUB_TOKEN instead.

GitHub Actions

For workflows in an organization-owned repository, grant the built-in token permission to make Copilot requests:

permissions:
  contents: read
  copilot-requests: write

jobs:
  copilot:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - run: your-application
        env:
          GITHUB_TOKEN: $

The organization's Allow use of Copilot CLI billed to the organization policy must be enabled. This approach needs no GitHub App or stored authentication secret. For details, see GITHUB_TOKEN을 사용한 GitHub Actions에서 Copilot CLI 사용하기.

Other services and CI systems

For services outside GitHub Actions:

  1. Create a GitHub App with the Copilot Requests repository permission set to Read & write.

  2. Install it on the organization that should be billed. The current Copilot permission check requires All repositories access.

  3. GitHub 앱에 대한 설치 액세스 토큰 생성 with a repository ID and the Copilot permission:

    {
      "repository_ids": [123456789],
      "permissions": {
        "copilot_requests": "write"
      }
    }
    
  4. Pass the resulting ghs_ token to the runtime as COPILOT_GITHUB_TOKEN.

The organization must be enabled for Copilot requests from GitHub App installations. Installation tokens expire after one hour.

경고

Do not pass an installation token through the SDK's gitHubToken, github_token, or equivalent option. That option is for user tokens. Installation tokens must use the runtime environment authentication path.

Configure the runtime

The following examples assume the minted token is in INSTALLATION_TOKEN. They pass it only to the child runtime and disable fallback to stored user credentials.

코드 언어 navigation

TypeScript
import { CopilotClient, RuntimeConnection } from "@github/copilot-sdk";

const token = process.env.INSTALLATION_TOKEN;
if (!token) throw new Error("INSTALLATION_TOKEN is required");

const client = new CopilotClient({
    connection: RuntimeConnection.forStdio(),
    env: {
        ...process.env,
        COPILOT_GITHUB_TOKEN: token,
    },
    useLoggedInUser: false,
});

For in-process FFI, set COPILOT_GITHUB_TOKEN in the host environment before loading the runtime; per-client environment options are not supported. For an existing runtime URI, set it on that runtime process.

Refresh tokens

Mint a new installation token before the current token expires. For a child process, restart the SDK client with the new environment. For an in-process or existing runtime, restart the host runtime with the new token.

Billing

Usage is attributed and billed to the account that owns the GitHub App installation. Use an organization installation for organization billing; a user-account installation attributes usage to that user.

Troubleshooting

SymptomCheck
401 UnauthorizedConfirm the organization supports GitHub App installation authentication for Copilot.
403 Resource not accessible by integration or an error mentioning user informationConfirm the installation token is in COPILOT_GITHUB_TOKEN, not the SDK's explicit token option.
403 Forbidden from the Copilot APIConfirm the token request contains repository_ids and copilot_requests: write.
403 Forbidden with the required token requestConfirm the app installation has All repositories access, then mint a new token.
Requested model is unavailableConfirm the organization's Copilot policy allows the model and the bundled runtime supports it.
Wrong account billedConfirm the installation belongs to the intended organization.

Further reading