Skip to content

Commit 75cd246

Browse files
feat: add blob attachment type for inline base64 data
Add support for a new 'blob' attachment type that allows sending base64-encoded content (e.g. images) directly without disk I/O. - Regenerate types for all 4 SDKs from updated session-events schema - Add BlobAttachment to Node.js and Python hand-written types - Export attachment types from Python SDK public API - Update docs: image-input.md, all language READMEs, streaming-events.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7766b1a commit 75cd246

File tree

14 files changed

+357
-20
lines changed

14 files changed

+357
-20
lines changed

docs/features/image-input.md

Lines changed: 193 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Image Input
22

3-
Send images to Copilot sessions by attaching them as file attachments. The runtime reads the file from disk, converts it to base64 internally, and sends it to the LLM as an image content block — no manual encoding required.
3+
Send images to Copilot sessions as attachments. There are two ways to attach images:
4+
5+
- **File attachment** (`type: "file"`) — provide an absolute path; the runtime reads the file from disk, converts it to base64, and sends it to the LLM.
6+
- **Blob attachment** (`type: "blob"`) — provide base64-encoded data directly; useful when the image is already in memory (e.g., screenshots, generated images, or data from an API).
47

58
## Overview
69

@@ -25,11 +28,12 @@ sequenceDiagram
2528
| Concept | Description |
2629
|---------|-------------|
2730
| **File attachment** | An attachment with `type: "file"` and an absolute `path` to an image on disk |
28-
| **Automatic encoding** | The runtime reads the image, converts it to base64, and sends it as an `image_url` block |
31+
| **Blob attachment** | An attachment with `type: "blob"`, base64-encoded `data`, and a `mimeType` — no disk I/O needed |
32+
| **Automatic encoding** | For file attachments, the runtime reads the image and converts it to base64 automatically |
2933
| **Auto-resize** | The runtime automatically resizes or quality-reduces images that exceed model-specific limits |
3034
| **Vision capability** | The model must have `capabilities.supports.vision = true` to process images |
3135

32-
## Quick Start
36+
## Quick Start — File Attachment
3337

3438
Attach an image file to any message using the file attachment type. The path must be an absolute path to an image on disk.
3539

@@ -215,9 +219,190 @@ await session.SendAsync(new MessageOptions
215219

216220
</details>
217221

222+
## Quick Start — Blob Attachment
223+
224+
When you already have image data in memory (e.g., a screenshot captured by your app, or an image fetched from an API), use a blob attachment to send it directly without writing to disk.
225+
226+
<details open>
227+
<summary><strong>Node.js / TypeScript</strong></summary>
228+
229+
```typescript
230+
import { CopilotClient } from "@github/copilot-sdk";
231+
232+
const client = new CopilotClient();
233+
await client.start();
234+
235+
const session = await client.createSession({
236+
model: "gpt-4.1",
237+
onPermissionRequest: async () => ({ kind: "approved" }),
238+
});
239+
240+
const base64ImageData = "..."; // your base64-encoded image
241+
await session.send({
242+
prompt: "Describe what you see in this image",
243+
attachments: [
244+
{
245+
type: "blob",
246+
data: base64ImageData,
247+
mimeType: "image/png",
248+
displayName: "screenshot.png",
249+
},
250+
],
251+
});
252+
```
253+
254+
</details>
255+
256+
<details>
257+
<summary><strong>Python</strong></summary>
258+
259+
```python
260+
from copilot import CopilotClient
261+
from copilot.types import PermissionRequestResult
262+
263+
client = CopilotClient()
264+
await client.start()
265+
266+
session = await client.create_session({
267+
"model": "gpt-4.1",
268+
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
269+
})
270+
271+
base64_image_data = "..." # your base64-encoded image
272+
await session.send({
273+
"prompt": "Describe what you see in this image",
274+
"attachments": [
275+
{
276+
"type": "blob",
277+
"data": base64_image_data,
278+
"mimeType": "image/png",
279+
"displayName": "screenshot.png",
280+
},
281+
],
282+
})
283+
```
284+
285+
</details>
286+
287+
<details>
288+
<summary><strong>Go</strong></summary>
289+
290+
<!-- docs-validate: hidden -->
291+
```go
292+
package main
293+
294+
import (
295+
"context"
296+
copilot "github.com/github/copilot-sdk/go"
297+
)
298+
299+
func main() {
300+
ctx := context.Background()
301+
client := copilot.NewClient(nil)
302+
client.Start(ctx)
303+
304+
session, _ := client.CreateSession(ctx, &copilot.SessionConfig{
305+
Model: "gpt-4.1",
306+
OnPermissionRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (copilot.PermissionRequestResult, error) {
307+
return copilot.PermissionRequestResult{Kind: copilot.PermissionRequestResultKindApproved}, nil
308+
},
309+
})
310+
311+
base64ImageData := "..."
312+
mimeType := "image/png"
313+
displayName := "screenshot.png"
314+
session.Send(ctx, copilot.MessageOptions{
315+
Prompt: "Describe what you see in this image",
316+
Attachments: []copilot.Attachment{
317+
{
318+
Type: copilot.Blob,
319+
Data: &base64ImageData,
320+
MIMEType: &mimeType,
321+
DisplayName: &displayName,
322+
},
323+
},
324+
})
325+
}
326+
```
327+
<!-- /docs-validate: hidden -->
328+
329+
```go
330+
mimeType := "image/png"
331+
displayName := "screenshot.png"
332+
session.Send(ctx, copilot.MessageOptions{
333+
Prompt: "Describe what you see in this image",
334+
Attachments: []copilot.Attachment{
335+
{
336+
Type: copilot.Blob,
337+
Data: &base64ImageData, // base64-encoded string
338+
MIMEType: &mimeType,
339+
DisplayName: &displayName,
340+
},
341+
},
342+
})
343+
```
344+
345+
</details>
346+
347+
<details>
348+
<summary><strong>.NET</strong></summary>
349+
350+
<!-- docs-validate: hidden -->
351+
```csharp
352+
using GitHub.Copilot.SDK;
353+
354+
public static class BlobAttachmentExample
355+
{
356+
public static async Task Main()
357+
{
358+
await using var client = new CopilotClient();
359+
await using var session = await client.CreateSessionAsync(new SessionConfig
360+
{
361+
Model = "gpt-4.1",
362+
OnPermissionRequest = (req, inv) =>
363+
Task.FromResult(new PermissionRequestResult { Kind = PermissionRequestResultKind.Approved }),
364+
});
365+
366+
var base64ImageData = "...";
367+
await session.SendAsync(new MessageOptions
368+
{
369+
Prompt = "Describe what you see in this image",
370+
Attachments = new List<UserMessageDataAttachmentsItem>
371+
{
372+
new UserMessageDataAttachmentsItemBlob
373+
{
374+
Data = base64ImageData,
375+
MimeType = "image/png",
376+
DisplayName = "screenshot.png",
377+
},
378+
},
379+
});
380+
}
381+
}
382+
```
383+
<!-- /docs-validate: hidden -->
384+
385+
```csharp
386+
await session.SendAsync(new MessageOptions
387+
{
388+
Prompt = "Describe what you see in this image",
389+
Attachments = new List<UserMessageDataAttachmentsItem>
390+
{
391+
new UserMessageDataAttachmentsItemBlob
392+
{
393+
Data = base64ImageData,
394+
MimeType = "image/png",
395+
DisplayName = "screenshot.png",
396+
},
397+
},
398+
});
399+
```
400+
401+
</details>
402+
218403
## Supported Formats
219404

220-
Supported image formats include JPG, PNG, GIF, and other common image types. The runtime reads the image from disk and converts it as needed before sending to the LLM. Use PNG or JPEG for best results, as these are the most widely supported formats.
405+
Supported image formats include JPG, PNG, GIF, and other common image types. For file attachments, the runtime reads the image from disk and converts it as needed. For blob attachments, you provide the base64 data and MIME type directly. Use PNG or JPEG for best results, as these are the most widely supported formats.
221406

222407
The model's `capabilities.limits.vision.supported_media_types` field lists the exact MIME types it accepts.
223408

@@ -283,10 +468,10 @@ These image blocks appear in `tool.execution_complete` event results. See the [S
283468
|-----|---------|
284469
| **Use PNG or JPEG directly** | Avoids conversion overhead — these are sent to the LLM as-is |
285470
| **Keep images reasonably sized** | Large images may be quality-reduced, which can lose important details |
286-
| **Use absolute paths** | The runtime reads files from disk; relative paths may not resolve correctly |
287-
| **Check vision support first** | Sending images to a non-vision model wastes tokens on the file path without visual understanding |
288-
| **Multiple images are supported** | Attach several file attachments in one message, up to the model's `max_prompt_images` limit |
289-
| **Images are not base64 in your code** | You provide a file path — the runtime handles encoding, resizing, and format conversion |
471+
| **Use absolute paths for file attachments** | The runtime reads files from disk; relative paths may not resolve correctly |
472+
| **Use blob attachments for in-memory data** | When you already have base64 data (e.g., screenshots, API responses), blob avoids unnecessary disk I/O |
473+
| **Check vision support first** | Sending images to a non-vision model wastes tokens without visual understanding |
474+
| **Multiple images are supported** | Attach several attachments in one message, up to the model's `max_prompt_images` limit |
290475
| **SVG is not supported** | SVG files are text-based and excluded from image processing |
291476

292477
## See Also

docs/features/streaming-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ The user sent a message. Recorded for the session timeline.
639639
|------------|------|----------|-------------|
640640
| `content` | `string` || The user's message text |
641641
| `transformedContent` | `string` | | Transformed version after preprocessing |
642-
| `attachments` | `Attachment[]` | | File, directory, selection, or GitHub reference attachments |
642+
| `attachments` | `Attachment[]` | | File, directory, selection, blob, or GitHub reference attachments |
643643
| `source` | `string` | | Message source identifier |
644644
| `agentMode` | `string` | | Agent mode: `"interactive"`, `"plan"`, `"autopilot"`, or `"shell"` |
645645
| `interactionId` | `string` | | CAPI interaction ID |

dotnet/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,35 @@ session.On(evt =>
265265

266266
## Image Support
267267

268-
The SDK supports image attachments via the `Attachments` parameter. You can attach images by providing their file path:
268+
The SDK supports image attachments via the `Attachments` parameter. You can attach images by providing their file path, or by passing base64-encoded data directly using a blob attachment:
269269

270270
```csharp
271+
// File attachment — runtime reads from disk
271272
await session.SendAsync(new MessageOptions
272273
{
273274
Prompt = "What's in this image?",
274275
Attachments = new List<UserMessageDataAttachmentsItem>
275276
{
276-
new UserMessageDataAttachmentsItem
277+
new UserMessageDataAttachmentsItemFile
277278
{
278-
Type = UserMessageDataAttachmentsItemType.File,
279279
Path = "/path/to/image.jpg"
280280
}
281281
}
282282
});
283+
284+
// Blob attachment — provide base64 data directly
285+
await session.SendAsync(new MessageOptions
286+
{
287+
Prompt = "What's in this image?",
288+
Attachments = new List<UserMessageDataAttachmentsItem>
289+
{
290+
new UserMessageDataAttachmentsItemBlob
291+
{
292+
Data = base64ImageData,
293+
MimeType = "image/png",
294+
}
295+
}
296+
});
283297
```
284298

285299
Supported image formats include JPG, PNG, GIF, and other common image types. The agent's `view` tool can also read images directly from the filesystem, so you can also ask questions like:

dotnet/src/Generated/SessionEvents.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,13 +1870,30 @@ public partial class UserMessageDataAttachmentsItemGithubReference : UserMessage
18701870
public required string Url { get; set; }
18711871
}
18721872

1873+
public partial class UserMessageDataAttachmentsItemBlob : UserMessageDataAttachmentsItem
1874+
{
1875+
[JsonIgnore]
1876+
public override string Type => "blob";
1877+
1878+
[JsonPropertyName("data")]
1879+
public required string Data { get; set; }
1880+
1881+
[JsonPropertyName("mimeType")]
1882+
public required string MimeType { get; set; }
1883+
1884+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1885+
[JsonPropertyName("displayName")]
1886+
public string? DisplayName { get; set; }
1887+
}
1888+
18731889
[JsonPolymorphic(
18741890
TypeDiscriminatorPropertyName = "type",
18751891
UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToBaseType)]
18761892
[JsonDerivedType(typeof(UserMessageDataAttachmentsItemFile), "file")]
18771893
[JsonDerivedType(typeof(UserMessageDataAttachmentsItemDirectory), "directory")]
18781894
[JsonDerivedType(typeof(UserMessageDataAttachmentsItemSelection), "selection")]
18791895
[JsonDerivedType(typeof(UserMessageDataAttachmentsItemGithubReference), "github_reference")]
1896+
[JsonDerivedType(typeof(UserMessageDataAttachmentsItemBlob), "blob")]
18801897
public partial class UserMessageDataAttachmentsItem
18811898
{
18821899
[JsonPropertyName("type")]
@@ -2365,6 +2382,7 @@ public enum PermissionCompletedDataResultKind
23652382
[JsonSerializable(typeof(UserInputRequestedEvent))]
23662383
[JsonSerializable(typeof(UserMessageData))]
23672384
[JsonSerializable(typeof(UserMessageDataAttachmentsItem))]
2385+
[JsonSerializable(typeof(UserMessageDataAttachmentsItemBlob))]
23682386
[JsonSerializable(typeof(UserMessageDataAttachmentsItemDirectory))]
23692387
[JsonSerializable(typeof(UserMessageDataAttachmentsItemDirectoryLineRange))]
23702388
[JsonSerializable(typeof(UserMessageDataAttachmentsItemFile))]

go/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
178178

179179
## Image Support
180180

181-
The SDK supports image attachments via the `Attachments` field in `MessageOptions`. You can attach images by providing their file path:
181+
The SDK supports image attachments via the `Attachments` field in `MessageOptions`. You can attach images by providing their file path, or by passing base64-encoded data directly using a blob attachment:
182182

183183
```go
184+
// File attachment — runtime reads from disk
184185
_, err = session.Send(context.Background(), copilot.MessageOptions{
185186
Prompt: "What's in this image?",
186187
Attachments: []copilot.Attachment{
@@ -190,6 +191,19 @@ _, err = session.Send(context.Background(), copilot.MessageOptions{
190191
},
191192
},
192193
})
194+
195+
// Blob attachment — provide base64 data directly
196+
mimeType := "image/png"
197+
_, err = session.Send(context.Background(), copilot.MessageOptions{
198+
Prompt: "What's in this image?",
199+
Attachments: []copilot.Attachment{
200+
{
201+
Type: copilot.Blob,
202+
Data: &base64ImageData,
203+
MIMEType: &mimeType,
204+
},
205+
},
206+
})
193207
```
194208

195209
Supported image formats include JPG, PNG, GIF, and other common image types. The agent's `view` tool can also read images directly from the filesystem, so you can also ask questions like:

go/generated_session_events.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)