Skip to main content
The GitHub Copilot integration is a self-hosted utility script that reads your enterprise’s Copilot usage records, rebuilds each conversation, and ingests every user/assistant turn into Nebuly as an Interaction. The data flow is: Usage records (REST API, or audit log stream in S3 / Azure Blob) → request/response pairing → interaction assembly → Nebuly ingestion The script is incremental and resumable: it tracks a local SQLite cache of already-synced data, so you can re-run it safely at any time without creating duplicates. If your organization signs in with Microsoft Entra, the same script can enrich each interaction with directory data. See Enrich with Microsoft Entra. The source repository is available here.
Copilot usage records are a GitHub public preview. GitHub can change the record format, and the script drops records it cannot parse. Check the Limitations before rolling this out.

Prerequisites

  • A GitHub Enterprise Cloud enterprise that uses Enterprise Managed Users (EMU). Usage records are not available to other enterprise types.
  • An enterprise owner who can create a token and change Copilot policies in AI controls.
  • The Copilot Usage Records API policy set to Enabled everywhere, and Copilot Usage Records Streaming too if you want older history (see Get your credentials).
  • Python ≥ 3.12 and Poetry installed on the machine that runs the script.
  • Optional: an audit log stream into Amazon S3 or Azure Blob Storage, if you want history older than 48 hours. See Backfill from an audit log stream.
Usage records cover Copilot in VS Code, Visual Studio, JetBrains IDEs, Eclipse, the Copilot CLI and the Copilot cloud agent. github.com chat, GitHub Mobile, Xcode, Slack and Teams do not appear in usage records, so they cannot be synced.

Install & run

Clone the integration examples repository, install dependencies, configure your .env file, and run the sync:
The REST API only returns the last 48 hours of usage records. The first run can backfill at most that window. To import older history, stream your audit log to S3 or Azure Blob and follow Backfill from an audit log stream.
Three optional settings change what you see in Nebuly: Follow the guide below to retrieve the necessary credentials. For the complete environment variable reference, available CLI flags, payload customization and resumable-cache details, check the project README.

Get your credentials

The script requires three environment variables. Follow the steps below to enable usage records and obtain each value.
1

Enable usage records in GitHub

An enterprise owner turns the feature on for the whole enterprise.
  1. In GitHub, open your enterprise and click AI controls, then Copilot in the sidebar.
  2. Set the Copilot Usage Records API policy to Enabled everywhere. This allows the script to read records over REST.
  3. If you also want to stream records to S3 or Azure Blob for older history, set the Copilot Usage Records Streaming policy to Enabled everywhere.
GitHub’s REST reference also says the general Copilot usage metrics policy must be Enabled everywhere for its Copilot metrics endpoints. GitHub’s usage records instructions list only the two policies above, but if the check below returns 403, make sure that one is enabled too.Policy labels can move while the feature is in preview. If you cannot find one of them, search the Copilot page in AI controls for “usage records” or check GitHub’s REST API endpoints for Copilot usage metrics page.
2

Nebuly secret key → NEBULY_API_KEY

In Nebuly, go to Settings → Projects → View Nebuly keys → Secret keys and copy the secret key for the project you want to sync.
3

GitHub token → GITHUB_TOKEN

The token must belong to an enterprise owner, because only enterprise owners can read usage records.
  1. In GitHub, click your profile picture, then Settings → Developer settings → Personal access tokens → Tokens (classic).
  2. Click Generate new token, then Generate new token (classic).
  3. Give the token a name, for example nebuly-copilot-sync.
  4. Choose an expiration that matches your rotation policy.
  5. Select the read:enterprise scope. Do not grant other scopes: the script only reads.
  6. Click Generate token and copy the value immediately; it is shown only once.
This token can read the prompts and responses of every Copilot user in the enterprise. Treat it like a root credential and store it in a secrets manager.
Resolving a user’s email (RESOLVE_USERS=true) reads your enterprise’s external identities, from SAML single sign-on or from OIDC (for example Microsoft Entra ID). An enterprise owner token with read:enterprise can see them. If the identities are not visible, the script logs one warning and uses the GitHub login as end_user instead.If your enterprise restricts personal access tokens (classic) under Policies → Personal access tokens, GitHub documents that policy as blocking access to the enterprise’s organizations and does not say whether it affects enterprise endpoints. If you cannot create the token, or the check below returns 403 even with the right scope, ask your enterprise owner to review that policy.
4

Enterprise slug → GITHUB_ENTERPRISE

Your enterprise slug is the last part of your enterprise URL: https://github.com/enterprises/<slug>. Copy <slug>. If your enterprise uses GHE.com data residency, the slug is the subdomain in https://<slug>.ghe.com, and you also set GITHUB_API_URL=https://api.<slug>.ghe.com in .env.
5

Check access

Request one usage record to confirm the token and the enterprise slug work together:
A working setup returns a JSON array of usage records. The values below are placeholders, and the exact shape can change while the API is in preview:
An empty array means no Copilot activity in the last 48 hours. A 401 means the token is wrong or expired. A 403 means the token is not an enterprise owner token, lacks the read:enterprise scope, or the policies from the first step are not enabled. A 404 usually means a wrong enterprise slug or an enterprise that is not eligible for usage records.

Backfill from an audit log stream (optional)

GitHub keeps usage records on the REST API for 48 hours only. If you want to import older history, or you cannot run the script at least daily, stream your enterprise audit log into a bucket you own and let the script read from it. Streaming only captures activity from the moment you enable it, so set it up before you need the data. Set up one of the two destinations below, then run the script with the matching source:
Use --sources rest,azure_blob for Azure Blob Storage. Each source keeps its own progress, so adding a stream source does not resend what REST already read.
The script lists every object under the prefix on every run. Point S3_PREFIX or AZURE_BLOB_PREFIX at the folder that holds the usage records, and archive or expire old objects, so the listing stays small.

Amazon S3

1

Create the bucket and let GitHub write to it

Create an S3 bucket with public access blocked. To avoid storing long-lived AWS keys in GitHub, use OpenID Connect: add GitHub as an IAM OIDC provider and create a role that GitHub can assume, with s3:PutObject permission on the bucket’s objects. GitHub’s Streaming the audit log for your enterprise guide lists the provider URL, audience and trust policy values.
2

Configure the stream in GitHub

  1. In GitHub, open your enterprise and click Settings → Audit log → Log streaming.
  2. Open the Configure stream dropdown and choose Amazon S3.
  3. Under Authentication, choose OpenID Connect (recommended) or Access keys.
  4. Choose the bucket region and enter the bucket name, plus the role ARN (OpenID Connect) or the access key ID and secret key.
  5. Click Check endpoint, then Save.
Also make sure the Copilot Usage Records Streaming policy from Get your credentials is turned on.
3

Point the script at the bucket

Set these in .env:
The script reads AWS credentials from the standard AWS credential chain (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, or an instance role). Give that identity read-only access: s3:ListBucket on the bucket and s3:GetObject on its objects. Use a separate identity from the one GitHub writes with.

Azure Blob Storage

1

Create a write-only SAS URL for GitHub

  1. In the Azure portal, go to Storage Accounts, select your account, then Data storage → Containers and your container.
  2. Under Settings, click Shared access tokens.
  3. In Permissions, select only Create and Write.
  4. Set an expiry date that matches your secret rotation policy.
  5. Click Generate SAS token and URL and copy the Blob SAS URL.
2

Configure the stream in GitHub

  1. In GitHub, open your enterprise and click Settings → Audit log → Log streaming.
  2. Open the Configure stream dropdown and choose Azure Blob Storage.
  3. Paste the Blob SAS URL. The container name fills in automatically.
  4. Click Check endpoint, then Save.
Also make sure the Copilot Usage Records Streaming policy from Get your credentials is turned on. Azure Government is not supported by GitHub audit log streaming.
3

Point the script at the container

Create a second, read-only credential for the script: either a SAS token with Read and List permissions, or a storage account connection string. Then set in .env:

What is synced

By default the script syncs one source, rest. Choose sources with --sources, a comma-separated list of rest, s3 and azure_blob. Only Copilot chat calls are synced. Completions, next edit suggestions and embeddings are skipped, and so are background helper calls such as chat title generation. When Copilot works as an agent and calls several tools in a row, those calls are grouped into one turn, so each interaction is one user request and the final answer. end_user is the user’s email when it can be resolved, otherwise their GitHub login, otherwise github-user-<id>. Each interaction carries tags taken from the usage record. Empty values are omitted. Tool calls made during the turn are attached to the interaction as retrieval traces. Input and output token counts are included when the record carries them. The script does not send a cost: Nebuly estimates it from the model and the token counts. Message content longer than 8,000 characters is truncated.

Export to CSV (optional)

To review the data before sending anything to Nebuly, write it to a local CSV file instead:
NEBULY_API_KEY is not required in this mode and nothing is sent to Nebuly. Each interaction becomes one row, with the same fields, tags and traces that Nebuly would receive. The file defaults to ./interactions.csv; set CSV_EXPORT_PATH to change it. Rows are appended on every run, so use a new file to start fresh. Exporting to CSV keeps its own progress and does not mark data as sent: when you later switch to Nebuly, the data is sent again, as long as it is still within the 48-hour REST window or present in your audit log stream.

Limitations

  • Public preview. The usage records API and its record format can change. Records the script cannot parse are skipped.
  • 48-hour REST window. The REST API returns only the last 48 hours. Run the script at least daily, ideally hourly, or stream to S3 or Azure Blob for longer retention.
  • Conversations are rebuilt. GitHub does not send a conversation id. The script derives one from the user and the opening message, split by CONVERSATION_GAP_HOURS. Two parallel conversations from the same user that start with the same text can share an id.
  • Not every surface. github.com chat, GitHub Mobile, Xcode, Slack and Teams do not appear in usage records.
  • Cost is an estimate. GitHub usage records have no spend field. Any cost in Nebuly is estimated from the model and tokens, and does not reflect GitHub’s bill. Tokens appear only when the record includes usage.
  • Large records. When a usage record is flagged as truncated, the interaction gets the truncated tag. GitHub’s reference does not document that flag yet. Input and output sent to Nebuly are capped at 8,000 characters.
  • Helper calls. A background call the script does not recognize is ingested as a normal turn. You can extend the filter, see the project README.
  • Email needs external identities. Mapping a GitHub login to an email needs an enterprise owner token and an enterprise that signs in with SAML or OIDC. When the identities are not visible, end_user is the login.
  • Azure Event Hubs and other stream destinations are not supported. Use S3 or Azure Blob Storage.
  • Team, market and tenure are only available through the Entra enrichment.

Enrich with Microsoft Entra

Usage records do not include team, market or tenure. If your GitHub users sign in with Microsoft, the sync can add them from your Entra directory. Register the Entra app and pick how the directory is loaded on the Microsoft Entra page, then set one of the two options in .env, not both:
Turn this on before the first sync. Interactions that were already sent are not updated. The join uses the email resolved from your enterprise’s SAML or OIDC identities, so it needs RESOLVE_USERS=true (see Limitations). When the email is resolved, end_user is already that email. See What gets added for the field mapping.

FAQ

Where does the synced data appear?
Conversations imported by the script show up on the Interactions page in your Nebuly project.
When will my data appear?
GitHub publishes usage records with a short delay, and there can be a further delay of up to 30 minutes between the moment the script sends data and when it becomes visible in Nebuly. A turn is also held until it is complete, which takes up to INTERACTION_IDLE_MINUTES (default 30). The script only syncs when you run it, so for ongoing sync schedule it (for example with cron). Because the REST API keeps only 48 hours, run it at least daily, ideally hourly.
Is it safe to re-run the script?
Yes. The script keeps a local cache of which records and interactions have already been processed. The cache is specific to your enterprise, sources and Nebuly project, so pointing the script at a new Nebuly project sends the data again (within what GitHub still retains). Re-running it against the same project will pick up only new data and will not create duplicates. Delete the cache directory to start over.
How can I see what would be sent without triggering ingestion?
Pass the --dry-run flag. The script will fetch and convert data but will skip the POST to Nebuly’s ingestion endpoint, printing a summary instead.
What happens if the script stops running for a while?
On the next run it continues from where it stopped. Data older than 48 hours is no longer on the REST API, so for gaps longer than that you need an audit log stream into S3 or Azure Blob. Streaming only captures activity from the day you turn it on.
Are token and cost included?
Tokens are included when GitHub’s record has them. Cost is not sent: Nebuly estimates it from the model and tokens, and it is not GitHub’s billed amount. See Limitations.
Why do some interactions have no team, market, or tenure?
Entra did not contain that user’s email, or the email could not be resolved from GitHub. Enable enrichment before the first sync. A later run does not update an interaction that was already sent.

Resources

GitHub Copilot Nebuly integration

Full install guide, env-var table, CLI flags, and customization docs

Copilot usage records API

GitHub’s REST reference for the enterprise usage records endpoint

Streaming the audit log

How to stream your enterprise audit log to Amazon S3 or Azure Blob Storage

Nebuly Interaction API

API reference for the Interaction ingestion endpoint