@@ -29,20 +29,49 @@ sequenceDiagram
2929
3030## Code samples
3131
32+ ### Prerequisites
33+
34+ Install the Azure Identity and Copilot SDK packages for your language:
35+
3236<details open >
3337<summary ><strong >.NET</strong ></summary >
3438
35- ### Prerequisites
36-
37- Install the required packages:
39+ <!-- docs-validate: skip -->
3840
3941``` bash
4042dotnet add package GitHub.Copilot.SDK
4143dotnet add package Azure.Core
4244```
4345
46+ </details >
47+ <details >
48+ <summary ><strong >Python</strong ></summary >
49+
50+ <!-- docs-validate: skip -->
51+
52+ ``` bash
53+ pip install github-copilot-sdk azure-identity
54+ ```
55+
56+ </details >
57+ <details >
58+ <summary ><strong >TypeScript</strong ></summary >
59+
60+ <!-- docs-validate: skip -->
61+
62+ ``` bash
63+ npm install @github/copilot-sdk @azure/identity
64+ ```
65+
66+ </details >
67+
4468### Basic usage
4569
70+ Get a token using ` DefaultAzureCredential ` and pass it as the ` bearer_token ` in your provider config:
71+
72+ <details open >
73+ <summary ><strong >.NET</strong ></summary >
74+
4675<!-- docs-validate: skip -->
4776
4877``` csharp
@@ -76,20 +105,9 @@ Console.WriteLine(response?.Data.Content);
76105```
77106
78107</details >
79-
80108<details >
81109<summary ><strong >Python</strong ></summary >
82110
83- ### Prerequisites
84-
85- Install the required packages:
86-
87- ``` bash
88- pip install github-copilot-sdk azure-identity
89- ```
90-
91- ### Basic usage
92-
93111<!-- docs-validate: skip -->
94112
95113``` python
@@ -133,9 +151,46 @@ async def main():
133151asyncio.run(main())
134152```
135153
154+ </details >
155+ <details >
156+ <summary ><strong >TypeScript</strong ></summary >
157+
158+ <!-- docs-validate: skip -->
159+
160+ ``` typescript
161+ import { DefaultAzureCredential } from " @azure/identity" ;
162+ import { CopilotClient } from " @github/copilot-sdk" ;
163+
164+ const credential = new DefaultAzureCredential ({
165+ requiredEnvVars: [" AZURE_TOKEN_CREDENTIALS" ],
166+ });
167+ const tokenResponse = await credential .getToken (
168+ " https://ai.azure.com/.default"
169+ );
170+
171+ const client = new CopilotClient ();
172+
173+ const session = await client .createSession ({
174+ model: " gpt-5.5" ,
175+ provider: {
176+ type: " openai" ,
177+ baseUrl: ` ${process .env .FOUNDRY_RESOURCE_URL }/openai/v1/ ` ,
178+ bearerToken: tokenResponse .token ,
179+ wireApi: " responses" ,
180+ },
181+ });
182+
183+ const response = await session .sendAndWait ({ prompt: " Hello!" });
184+ console .log (response ?.data .content );
185+
186+ await client .stop ();
187+ ```
188+
189+ </details >
190+
136191### Token refresh for long-running applications
137192
138- Bearer tokens expire (typically after ~ 1 hour). For servers or long-running agents, refresh the token before creating each session:
193+ Bearer tokens expire (typically after ~ 1 hour). For servers or long-running agents, refresh the token before creating each session. The following Python example demonstrates this pattern :
139194
140195<!-- docs-validate: skip -->
141196
@@ -181,54 +236,6 @@ class ManagedIdentityCopilotAgent:
181236 return response.data.content if response else " "
182237```
183238
184- </details >
185-
186- <details >
187- <summary ><strong >TypeScript</strong ></summary >
188-
189- ### Prerequisites
190-
191- Install the required packages:
192-
193- ``` bash
194- npm install @github/copilot-sdk @azure/identity
195- ```
196-
197- ### Basic usage
198-
199- <!-- docs-validate: skip -->
200-
201- ``` typescript
202- import { DefaultAzureCredential } from " @azure/identity" ;
203- import { CopilotClient } from " @github/copilot-sdk" ;
204-
205- const credential = new DefaultAzureCredential ({
206- requiredEnvVars: [" AZURE_TOKEN_CREDENTIALS" ],
207- });
208- const tokenResponse = await credential .getToken (
209- " https://ai.azure.com/.default"
210- );
211-
212- const client = new CopilotClient ();
213-
214- const session = await client .createSession ({
215- model: " gpt-5.5" ,
216- provider: {
217- type: " openai" ,
218- baseUrl: ` ${process .env .FOUNDRY_RESOURCE_URL }/openai/v1/ ` ,
219- bearerToken: tokenResponse .token ,
220- wireApi: " responses" ,
221- },
222- });
223-
224- const response = await session .sendAndWait ({ prompt: " Hello!" });
225- console .log (response ?.data .content );
226-
227- await client .stop ();
228- ```
229-
230- </details >
231-
232239## Environment configuration
233240
234241| Variable | Description | Example |
0 commit comments