Liking cljdoc? Tell your friends :D

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: ${{ secrets.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 Using Copilot CLI in GitHub Actions with GITHUB_TOKEN.

Other services and CI systems

For services outside GitHub Actions:

  1. Create a GitHub App with the Copilot Requests organization permission set to Read-only.

  2. Install it on the organization that usage should be attributed and billed to.

  3. Create an installation access token with the Copilot permission:

    {
        "permissions": {
            "organization_copilot_requests": "read"
        }
    }
    
  4. Pass the resulting ghs_ token to the SDK's gitHubToken, github_token, or equivalent option. For an existing TCP runtime, set it as COPILOT_GITHUB_TOKEN on the runtime process instead.

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

note

No signed-in user is required. useLoggedInUser: false turns off automatic credential discovery, including environment variable tokens such as COPILOT_GITHUB_TOKEN, so pass the installation token through the SDK's explicit token option.

Configure the runtime

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

TypeScript
import { CopilotClient } from "copilot-sdk-supercharged";

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

const client = new CopilotClient({
    mode: "coding-agent",
    github: {
        token: token,
        useLoggedInUser: false,
    },
});
Python
import os

from copilot import CopilotClient

client = CopilotClient(
    mode="coding-agent",
    github={"token": os.environ["INSTALLATION_TOKEN"], "use_logged_in_user": False},
)
Go
package main

import (
	"log"
	"os"

	copilot "github.com/microsoft/copilot-sdk/go/v2"
)

func main() {
	token, ok := os.LookupEnv("INSTALLATION_TOKEN")
	if !ok {
		log.Fatal("INSTALLATION_TOKEN is required")
	}
	client := copilot.NewClient(&copilot.ClientOptions{
		Mode: copilot.ModeCodingAgent,
		GitHub: copilot.ClientGitHubOptions{
			Token:           token,
			UseLoggedInUser: copilot.Bool(false),
		},
		Runtime: copilot.SpawnedStdioConnection{},
	})
	_ = client
}
Rust
use copilot_sdk::ClientOptions;

fn main() {
    let token = std::env::var("INSTALLATION_TOKEN").expect("INSTALLATION_TOKEN is required");
    let options = ClientOptions::new(copilot_sdk::ClientMode::CodingAgent)
        .with_github(|__sdk_group| __sdk_group.with_token(token))
        .with_github(|__sdk_group| __sdk_group.with_use_logged_in_user(false));
    drop(options);
}
.NET
using Microsoft.Copilot;

var token = Environment.GetEnvironmentVariable("INSTALLATION_TOKEN") ?? throw new InvalidOperationException("INSTALLATION_TOKEN is required");
await using var client = new CopilotClient(new CopilotClientOptions
{
    Mode = CopilotClientMode.CodingAgent,
    GitHub = new ClientGitHubOptions
    {
        Token = token,
        UseLoggedInUser = false
    }
});
Java
import com.microsoft.copilot.rpc.CopilotClientMode;
import com.microsoft.copilot.CopilotClient;
import com.microsoft.copilot.rpc.CopilotClientOptions;
import java.util.Objects;
import com.microsoft.copilot.rpc.ClientGitHubOptions;

var token = Objects
        .requireNonNull(System
                .getenv("INSTALLATION_TOKEN"), "INSTALLATION_TOKEN is required");

try (var client = new CopilotClient(new CopilotClientOptions().setMode(CopilotClientMode.CODING_AGENT)
        .setGitHub(new ClientGitHubOptions()
                .setToken(token)
                .setUseLoggedInUser(false)))) {
    // Use the client.
}

For in-process FFI, use the same token option; environment variable tokens in the host process are ignored when useLoggedInUser is false. For an existing TCP runtime, set COPILOT_GITHUB_TOKEN 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 token. For an in-process or existing runtime, restart the host runtime with the new token.

Billing

Usage is attributed and billed to the organization that owns the GitHub App installation.

Troubleshooting

SymptomCheck
401 UnauthorizedThe token may be expired or invalid. Mint a new installation token.
403 stating that Copilot requests with GitHub App installation access tokens are not enabledConfirm the organization supports GitHub App installation authentication for Copilot.
This session is not signed in. (error code no_account) or Not authenticatedConfirm the installation token is passed through the SDK's explicit token option. With useLoggedInUser: false, the runtime ignores COPILOT_GITHUB_TOKEN and other environment variable tokens.
403 Forbidden from the Copilot APIConfirm the installation has the organization Copilot Requests permission, 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

Can you improve this documentation? These fine people already did:
copilot-sdk-mirror-writer[bot], copilot-cli-release-app[bot], Jeremiah Isaacson & Patrick Nikoletich
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close