Prerequisites
- A Microsoft 365 tenant with Copilot Enterprise licenses, and an admin who can grant tenant-wide API consent.
- Python ≥ 3.12 and Poetry installed on the machine that runs the script.
Install & run
Clone the integration examples repository, install dependencies, configure your.env file, and run the sync:
Get your credentials
The script requires four environment variables. Follow the steps below to obtain each one:NEBULY_API_KEY, AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET.
1
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.
2
Register an app in Microsoft Entra
- Open the Microsoft Entra admin center.
- Go to App registrations → New registration.
- Give the app a name.
- Under Supported account types, choose Single tenant only -
- Click Register.
3
Tenant & client IDs → AZURE_TENANT_ID / AZURE_CLIENT_ID
Go to App registrations → → Overview page, copy:
- Directory (tenant) ID →
AZURE_TENANT_ID - Application (client) ID →
AZURE_CLIENT_ID
4
Client secret → AZURE_CLIENT_SECRET
- Go to App registrations → → Certificates & secrets → New client secret.
- Add a description and expiration, then click Add.
- Copy the secret Value immediately. Use the Value, not the Secret ID, for
AZURE_CLIENT_SECRET.
5
Grant API permissions
- Go to App registrations → → API permissions → Add a permission.
- Select Microsoft Graph → Application permissions.
- Add
AiEnterpriseInteraction.Read.AllandUser.Read.All. - (Optional, for Purview audit enrichment) Add
AuditLogsQuery.Read.All— only required whenAUDIT_ENRICHMENT=true. - Click Grant admin consent for .
Purview audit enrichment (optional)
WhenAUDIT_ENRICHMENT=true, the sync queries Microsoft Graph audit log queries for CopilotInteraction records, caches them, and joins them to Graph interaction turns by message id.
Enable in .env
AUDIT_SETTLE_LAG_SECONDS— default7200(hold back the tail while audit records arrive)AUDIT_POLL_INTERVAL_SECONDS— default30AUDIT_QUERY_TIMEOUT_SECONDS— default3600
Tags when audit matches
The most valuable information for Nebuly is the model, as it can be used to enable certain features in the platform.
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?
There can be a delay of up to 30 minutes between the moment data is available in Microsoft Graph and when it becomes visible in Nebuly. Subsequent updates follow the same polling interval. Is it safe to re-run the script?
Yes. The script maintains a local SQLite cache at
.cache/sync_state.db that tracks per-user coverage windows. Re-running it will pick up only new data and will not create duplicates.
How can I see what would be sent without triggering ingestion?Use 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.
Are token, cost, and conversation metrics included?Microsoft Graph does not expose per-interaction token or cost data. Without audit enrichment, the sync sends retrieval (grounding) traces only. With
AUDIT_ENRICHMENT=true, an LLM trace is added only when Purview provides ModelName.
Why do Excel and PowerPoint Copilot turns appear as separate Nebuly conversations?For Excel and PowerPoint, Microsoft Graph often returns a different
sessionId (or requestId) on each turn, even when the user is continuing the same chat. Nebuly groups turns by that identifier, so multi-turn sessions in those apps usually import as one conversation per turn. This is a limitation of the export data from Microsoft, not the Nebuly sync.
How do I enable Purview audit enrichment?Grant
AuditLogsQuery.Read.All on your app registration, set AUDIT_ENRICHMENT=true in .env, and re-run the sync. Expect tail data to appear only after the audit settle window (AUDIT_SETTLE_LAG_SECONDS, default 2 hours). See Purview audit enrichment above.
Resources
Microsoft 365 Copilot Nebuly integration
Full install guide, env-var table, CLI flags, and customization docs
Export Microsoft Teams Copilot content
Microsoft’s official guide to exporting Copilot interaction data
Microsoft Graph audit log query API
API used for Purview CopilotInteraction audit enrichment
Nebuly Interaction API
API reference for the Interaction ingestion endpoint