-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdocumentation.html
More file actions
520 lines (471 loc) · 25.5 KB
/
Copy pathdocumentation.html
File metadata and controls
520 lines (471 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 2.0.0-M19 from src/site/markdown/documentation.md at 2026-01-26
| Rendered using Apache Maven Fluido Skin 2.0.0-M11
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0-M19" />
<title>Copilot SDK for Java - Documentation – GitHub Copilot Community SDK :: Java</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-2.0.0-M11.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script src="./js/apache-maven-fluido-2.0.0-M11.min.js"></script>
</head>
<body>
<div class="container-fluid container-fluid-top">
<header>
<div id="banner">
<div class="pull-left"></div>
<div class="pull-right"></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2026-01-26<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 1.0.2<span class="divider">|</span></li>
<li><a href="index.html">Home</a><span class="divider">/</span></li>
<li class="active">Copilot SDK for Java - Documentation</li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Overview</li>
<li><a href="index.html">Introduction</a></li>
<li class="active"><a>Documentation</a></li>
<li class="nav-header">Documentation</li>
<li><a href="documentation.html#API_Reference"><span class="icon-chevron-down"></span>API Reference</a>
<ul class="nav nav-list">
<li><a href="documentation.html#CopilotClient">CopilotClient</a></li>
<li><a href="documentation.html#CopilotSession">CopilotSession</a></li>
</ul></li>
<li><a href="documentation.html#Event_Types">Event Types</a></li>
<li><a href="documentation.html#Streaming">Streaming</a></li>
<li><a href="documentation.html#Listing_Models">Listing Models</a></li>
<li><a href="documentation.html#Advanced_Usage"><span class="icon-chevron-down"></span>Advanced Usage</a>
<ul class="nav nav-list">
<li><a href="documentation.html#Manual_Server_Control">Manual Server Control</a></li>
<li><a href="documentation.html#Tools">Tools</a></li>
<li><a href="documentation.html#System_Message_Customization">System Message Customization</a></li>
<li><a href="documentation.html#Multiple_Sessions">Multiple Sessions</a></li>
<li><a href="documentation.html#File_Attachments">File Attachments</a></li>
<li><a href="documentation.html#Bring_Your_Own_Key_.28BYOK.29">Bring Your Own Key (BYOK)</a></li>
<li><a href="documentation.html#Permission_Handling">Permission Handling</a></li>
</ul></li>
<li><a href="documentation.html#Error_Handling">Error Handling</a></li>
<li class="nav-header">Project Documentation</li>
<li><a href="project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li>
<li><a href="project-reports.html"><span class="icon-chevron-right"></span>Project Reports</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<a href="https://maven.apache.org/" class="builtBy" target="_blank"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10">
<section><a id="Copilot_SDK_for_Java_-_Documentation"></a>
<h1>Copilot SDK for Java - Documentation</h1>
<p>This document provides detailed API reference and usage examples for the Copilot SDK for Java.</p><section><a id="Table_of_Contents"></a>
<h2>Table of Contents</h2>
<ul>
<li><a href="#API_Reference">API Reference</a>
<ul>
<li><a href="#CopilotClient">CopilotClient</a></li>
<li><a href="#CopilotSession">CopilotSession</a></li>
</ul></li>
<li><a href="#Event_Types">Event Types</a></li>
<li><a href="#Streaming">Streaming</a></li>
<li><a href="#Listing_Models">Listing Models</a></li>
<li><a href="#Advanced_Usage">Advanced Usage</a>
<ul>
<li><a href="#Manual_Server_Control">Manual Server Control</a></li>
<li><a href="#Tools">Tools</a></li>
<li><a href="#System_Message_Customization">System Message Customization</a></li>
<li><a href="#Multiple_Sessions">Multiple Sessions</a></li>
<li><a href="#File_Attachments">File Attachments</a></li>
<li><a href="#Bring_Your_Own_Key_.28BYOK.29">Bring Your Own Key (BYOK)</a></li>
<li><a href="#Permission_Handling">Permission Handling</a></li>
<li><a href="#Infinite_Sessions">Infinite Sessions</a></li>
</ul></li>
<li><a href="#Error_Handling">Error Handling</a></li>
</ul></section><section><a id="API_Reference"></a>
<h2>API Reference</h2><section><a id="CopilotClient"></a>
<h3>CopilotClient</h3><section><a id="Constructor"></a>
<h4>Constructor</h4>
<pre class="prettyprint"><code class="language-java">new CopilotClient()
new CopilotClient(CopilotClientOptions options)
</code></pre>
<p><strong>Options:</strong></p>
<ul>
<li><code>cliPath</code> - Path to CLI executable (default: “copilot” from PATH)</li>
<li><code>cliArgs</code> - Extra arguments prepended before SDK-managed flags</li>
<li><code>cliUrl</code> - URL of existing CLI server to connect to (e.g., <code>"localhost:8080"</code>). When provided, the client will not spawn a CLI process.</li>
<li><code>port</code> - Server port (default: 0 for random)</li>
<li><code>useStdio</code> - Use stdio transport instead of TCP (default: true)</li>
<li><code>logLevel</code> - Log level (default: “info”)</li>
<li><code>autoStart</code> - Auto-start server (default: true)</li>
<li><code>autoRestart</code> - Auto-restart on crash (default: true)</li>
<li><code>cwd</code> - Working directory for the CLI process</li>
<li><code>environment</code> - Environment variables to pass to the CLI process</li>
</ul></section><section><a id="Methods"></a>
<h4>Methods</h4><section><a id="start.28.29.3A_CompletableFuture.3CVoid.3E"></a>
<h5><code>start(): CompletableFuture<Void></code></h5>
<p>Start the CLI server and establish connection.</p></section><section><a id="stop.28.29.3A_CompletableFuture.3CVoid.3E"></a>
<h5><code>stop(): CompletableFuture<Void></code></h5>
<p>Stop the server and close all sessions.</p></section><section><a id="forceStop.28.29.3A_CompletableFuture.3CVoid.3E"></a>
<h5><code>forceStop(): CompletableFuture<Void></code></h5>
<p>Force stop the CLI server without graceful cleanup.</p></section><section><a id="createSession.28SessionConfig_config.29.3A_CompletableFuture.3CCopilotSession.3E"></a>
<h5><code>createSession(SessionConfig config): CompletableFuture<CopilotSession></code></h5>
<p>Create a new conversation session.</p>
<p><strong>Config:</strong></p>
<ul>
<li><code>sessionId</code> - Custom session ID</li>
<li><code>model</code> - Model to use (“gpt-5”, “claude-sonnet-4.5”, etc.)</li>
<li><code>tools</code> - Custom tools exposed to the CLI</li>
<li><code>systemMessage</code> - System message customization</li>
<li><code>availableTools</code> - List of tool names to allow</li>
<li><code>excludedTools</code> - List of tool names to disable</li>
<li><code>provider</code> - Custom API provider configuration (BYOK)</li>
<li><code>streaming</code> - Enable streaming of response chunks (default: false)</li>
<li><code>mcpServers</code> - MCP server configurations</li>
<li><code>customAgents</code> - Custom agent configurations</li>
<li><code>onPermissionRequest</code> - Handler for permission requests</li>
</ul></section><section><a id="resumeSession.28String_sessionId.2C_ResumeSessionConfig_config.29.3A_CompletableFuture.3CCopilotSession.3E"></a>
<h5><code>resumeSession(String sessionId, ResumeSessionConfig config): CompletableFuture<CopilotSession></code></h5>
<p>Resume an existing session.</p></section><section><a id="ping.28String_message.29.3A_CompletableFuture.3CPingResponse.3E"></a>
<h5><code>ping(String message): CompletableFuture<PingResponse></code></h5>
<p>Ping the server to check connectivity.</p></section><section><a id="getStatus.28.29.3A_CompletableFuture.3CGetStatusResponse.3E"></a>
<h5><code>getStatus(): CompletableFuture<GetStatusResponse></code></h5>
<p>Get CLI status including version and protocol information.</p></section><section><a id="getAuthStatus.28.29.3A_CompletableFuture.3CGetAuthStatusResponse.3E"></a>
<h5><code>getAuthStatus(): CompletableFuture<GetAuthStatusResponse></code></h5>
<p>Get current authentication status.</p></section><section><a id="listModels.28.29.3A_CompletableFuture.3CList.3CModelInfo.3E.3E"></a>
<h5><code>listModels(): CompletableFuture<List<ModelInfo>></code></h5>
<p>List available models with their metadata (id, name, capabilities, billing info).</p></section><section><a id="getState.28.29.3A_ConnectionState"></a>
<h5><code>getState(): ConnectionState</code></h5>
<p>Get current connection state. Returns one of: <code>DISCONNECTED</code>, <code>CONNECTING</code>, <code>CONNECTED</code>, <code>ERROR</code>.</p></section><section><a id="listSessions.28.29.3A_CompletableFuture.3CList.3CSessionMetadata.3E.3E"></a>
<h5><code>listSessions(): CompletableFuture<List<SessionMetadata>></code></h5>
<p>List all available sessions.</p></section><section><a id="deleteSession.28String_sessionId.29.3A_CompletableFuture.3CVoid.3E"></a>
<h5><code>deleteSession(String sessionId): CompletableFuture<Void></code></h5>
<p>Delete a session and its data from disk.</p></section><section><a id="getLastSessionId.28.29.3A_CompletableFuture.3CString.3E"></a>
<h5><code>getLastSessionId(): CompletableFuture<String></code></h5>
<p>Get the ID of the most recently used session.</p><hr /></section></section></section><section><a id="CopilotSession"></a>
<h3>CopilotSession</h3>
<p>Represents a single conversation session.</p><section><a id="Properties"></a>
<h4>Properties</h4>
<ul>
<li><code>getSessionId()</code> - The unique identifier for this session</li>
</ul></section><section><a id="Methods_1"></a>
<h4>Methods</h4><section><a id="send.28String_prompt.29.3A_CompletableFuture.3CString.3E"></a>
<h5><code>send(String prompt): CompletableFuture<String></code></h5>
<p>Convenience method to send a simple text message. Equivalent to <code>send(new MessageOptions().setPrompt(prompt))</code>.</p></section><section><a id="send.28MessageOptions_options.29.3A_CompletableFuture.3CString.3E"></a>
<h5><code>send(MessageOptions options): CompletableFuture<String></code></h5>
<p>Send a message to the session.</p>
<p><strong>Options:</strong></p>
<ul>
<li><code>prompt</code> - The message/prompt to send</li>
<li><code>attachments</code> - File attachments</li>
<li><code>mode</code> - Delivery mode (“enqueue” or “immediate”)</li>
</ul>
<p>Returns the message ID.</p></section><section><a id="sendAndWait.28String_prompt.29.3A_CompletableFuture.3CAssistantMessageEvent.3E"></a>
<h5><code>sendAndWait(String prompt): CompletableFuture<AssistantMessageEvent></code></h5>
<p>Convenience method to send a simple text message and wait for the session to become idle. Equivalent to <code>sendAndWait(new MessageOptions().setPrompt(prompt))</code>.</p></section><section><a id="sendAndWait.28MessageOptions_options.29.3A_CompletableFuture.3CAssistantMessageEvent.3E"></a>
<h5><code>sendAndWait(MessageOptions options): CompletableFuture<AssistantMessageEvent></code></h5>
<p>Send a message and wait for the session to become idle. Default timeout is 60 seconds.</p></section><section><a id="sendAndWait.28MessageOptions_options.2C_long_timeoutMs.29.3A_CompletableFuture.3CAssistantMessageEvent.3E"></a>
<h5><code>sendAndWait(MessageOptions options, long timeoutMs): CompletableFuture<AssistantMessageEvent></code></h5>
<p>Send a message and wait for the session to become idle with custom timeout.</p></section><section><a id="on.28Consumer.3CAbstractSessionEvent.3E_handler.29.3A_Closeable"></a>
<h5><code>on(Consumer<AbstractSessionEvent> handler): Closeable</code></h5>
<p>Subscribe to session events. Returns a <code>Closeable</code> to unsubscribe.</p>
<pre class="prettyprint"><code class="language-java">var subscription = session.on(evt -> {
System.out.println("Event: " + evt.getType());
});
// Later...
subscription.close();
</code></pre></section><section><a id="abort.28.29.3A_CompletableFuture.3CVoid.3E"></a>
<h5><code>abort(): CompletableFuture<Void></code></h5>
<p>Abort the currently processing message in this session.</p></section><section><a id="getMessages.28.29.3A_CompletableFuture.3CList.3CAbstractSessionEvent.3E.3E"></a>
<h5><code>getMessages(): CompletableFuture<List<AbstractSessionEvent>></code></h5>
<p>Get all events/messages from this session.</p></section><section><a id="close.28.29"></a>
<h5><code>close()</code></h5>
<p>Dispose the session and free resources.</p><hr /></section></section></section></section><section><a id="Event_Types"></a>
<h2>Event Types</h2>
<p>Sessions emit various events during processing. Each event type extends <code>AbstractSessionEvent</code>:</p>
<ul>
<li><code>UserMessageEvent</code> - User message added</li>
<li><code>AssistantMessageEvent</code> - Assistant response</li>
<li><code>AssistantMessageDeltaEvent</code> - Streaming response chunk</li>
<li><code>ToolExecutionStartEvent</code> - Tool execution started</li>
<li><code>ToolExecutionCompleteEvent</code> - Tool execution completed</li>
<li><code>SessionStartEvent</code> - Session started</li>
<li><code>SessionIdleEvent</code> - Session is idle</li>
<li><code>SessionErrorEvent</code> - Session error occurred</li>
<li><code>SessionResumeEvent</code> - Session was resumed</li>
<li>And more…</li>
</ul>
<p>Use pattern matching (Java 21+) to handle specific event types:</p>
<pre class="prettyprint"><code class="language-java">session.on(evt -> {
if (evt instanceof AssistantMessageEvent msg) {
System.out.println(msg.getData().getContent());
} else if (evt instanceof SessionErrorEvent err) {
System.out.println("Error: " + err.getData().getMessage());
}
});
</code></pre></section><section><a id="Streaming"></a>
<h2>Streaming</h2>
<p>Enable streaming to receive assistant response chunks as they're generated:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setStreaming(true)
).get();
var done = new CompletableFuture<Void>();
session.on(evt -> {
if (evt instanceof AssistantMessageDeltaEvent delta) {
// Streaming message chunk - print incrementally
System.out.print(delta.getData().getDeltaContent());
} else if (evt instanceof AssistantMessageEvent msg) {
// Final message - complete content
System.out.println("\n--- Final message ---");
System.out.println(msg.getData().getContent());
} else if (evt instanceof SessionIdleEvent) {
done.complete(null);
}
});
session.send(new MessageOptions().setPrompt("Tell me a short story")).get();
done.get();
</code></pre></section><section><a id="Listing_Models"></a>
<h2>Listing Models</h2>
<p>Query available models and their capabilities before creating a session:</p>
<pre class="prettyprint"><code class="language-java">try (var client = new CopilotClient()) {
client.start().get();
// List all available models
List<ModelInfo> models = client.listModels().get();
for (ModelInfo model : models) {
System.out.println("Model: " + model.getId());
System.out.println(" Name: " + model.getName());
if (model.getCapabilities() != null) {
System.out.println(" Max Output Tokens: " + model.getCapabilities().getMaxOutputTokens());
}
if (model.getPolicy() != null) {
System.out.println(" State: " + model.getPolicy().getState());
}
}
// Use a specific model from the list
var session = client.createSession(
new SessionConfig().setModel(models.get(0).getId())
).get();
}
</code></pre>
<p>Each <code>ModelInfo</code> contains:</p>
<ul>
<li><code>id</code> - Model identifier (e.g., “claude-sonnet-4.5”, “gpt-4o”)</li>
<li><code>name</code> - Human-readable display name</li>
<li><code>capabilities</code> - Model limits including max output tokens</li>
<li><code>policy</code> - Policy state information</li>
<li><code>billing</code> - Billing/usage information</li>
</ul></section><section><a id="Advanced_Usage"></a>
<h2>Advanced Usage</h2><section><a id="Manual_Server_Control"></a>
<h3>Manual Server Control</h3>
<pre class="prettyprint"><code class="language-java">var client = new CopilotClient(
new CopilotClientOptions().setAutoStart(false)
);
// Start manually
client.start().get();
// Use client...
// Stop manually
client.stop().get();
</code></pre></section><section><a id="Tools"></a>
<h3>Tools</h3>
<p>You can let the CLI call back into your process when the model needs capabilities you own:</p>
<pre class="prettyprint"><code class="language-java">var lookupTool = ToolDefinition.create(
"lookup_issue",
"Fetch issue details from our tracker",
Map.of(
"type", "object",
"properties", Map.of(
"id", Map.of("type", "string", "description", "Issue identifier")
),
"required", List.of("id")
),
invocation -> {
String id = ((Map<String, Object>) invocation.getArguments()).get("id").toString();
return CompletableFuture.completedFuture(fetchIssue(id));
}
);
var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setTools(List.of(lookupTool))
).get();
</code></pre></section><section><a id="System_Message_Customization"></a>
<h3>System Message Customization</h3>
<p>Control the system prompt using <code>SystemMessageConfig</code> in session config:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setSystemMessage(new SystemMessageConfig()
.setMode(SystemMessageMode.APPEND)
.setContent("""
<workflow_rules>
- Always check for security vulnerabilities
- Suggest performance improvements when applicable
</workflow_rules>
"""))
).get();
</code></pre>
<p>For full control (removes all guardrails), use <code>REPLACE</code> mode:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setSystemMessage(new SystemMessageConfig()
.setMode(SystemMessageMode.REPLACE)
.setContent("You are a helpful assistant."))
).get();
</code></pre></section><section><a id="Multiple_Sessions"></a>
<h3>Multiple Sessions</h3>
<pre class="prettyprint"><code class="language-java">var session1 = client.createSession(
new SessionConfig().setModel("gpt-5")
).get();
var session2 = client.createSession(
new SessionConfig().setModel("claude-sonnet-4.5")
).get();
// Both sessions are independent
session1.send(new MessageOptions().setPrompt("Hello from session 1")).get();
session2.send(new MessageOptions().setPrompt("Hello from session 2")).get();
</code></pre></section><section><a id="File_Attachments"></a>
<h3>File Attachments</h3>
<pre class="prettyprint"><code class="language-java">session.send(new MessageOptions()
.setPrompt("Analyze this file")
.setAttachments(List.of(
new Attachment()
.setType("file")
.setPath("/path/to/file.java")
.setDisplayName("My File")
))
).get();
</code></pre></section><section><a id="Bring_Your_Own_Key_.28BYOK.29"></a>
<h3>Bring Your Own Key (BYOK)</h3>
<p>Use a custom API provider:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setProvider(new ProviderConfig()
.setType("openai")
.setBaseUrl("https://api.openai.com/v1")
.setApiKey("your-api-key"))
).get();
</code></pre></section><section><a id="Permission_Handling"></a>
<h3>Permission Handling</h3>
<p>Handle permission requests from the CLI:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setOnPermissionRequest((request, invocation) -> {
// Approve or deny the permission request
var result = new PermissionRequestResult();
result.setKind("user-approved");
return CompletableFuture.completedFuture(result);
})
).get();
</code></pre></section><section><a id="Infinite_Sessions"></a>
<h3>Infinite Sessions</h3>
<p>Infinite sessions enable automatic context management for long-running conversations. When enabled (default), the session automatically manages context window limits through background compaction and persists state to a workspace directory.</p><section><a id="How_It_Works"></a>
<h4>How It Works</h4>
<p>As conversations grow, they eventually approach the model's context window limit. Infinite sessions solve this by:</p>
<ol style="list-style-type: decimal;">
<li>
<p><strong>Background Compaction</strong>: When context utilization reaches the background threshold (default 80%), the session starts compacting older messages asynchronously while continuing to process new messages.</p></li>
<li>
<p><strong>Buffer Exhaustion Protection</strong>: If context reaches the exhaustion threshold (default 95%) before compaction completes, the session blocks until compaction finishes to prevent overflow.</p></li>
<li>
<p><strong>Workspace Persistence</strong>: Session state is persisted to a workspace directory containing:</p>
<ul>
<li><code>checkpoints/</code> - Session checkpoints for resumption</li>
<li><code>plan.md</code> - Current conversation plan</li>
<li><code>files/</code> - Associated files</li>
</ul></li>
</ol></section><section><a id="Configuration"></a>
<h4>Configuration</h4>
<pre class="prettyprint"><code class="language-java">var infiniteConfig = new InfiniteSessionConfig()
.setEnabled(true)
.setBackgroundCompactionThreshold(0.80) // Start compacting at 80% utilization
.setBufferExhaustionThreshold(0.95); // Block at 95% until compaction completes
var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setInfiniteSessions(infiniteConfig)
).get();
</code></pre></section><section><a id="Configuration_Options"></a>
<h4>Configuration Options</h4>
<table class="table table-striped">
<thead>
<tr class="a">
<th>Option</th>
<th>Default</th>
<th>Description</th></tr></thead><tbody>
<tr class="b">
<td><code>enabled</code></td>
<td><code>true</code></td>
<td>Whether infinite sessions are enabled</td></tr>
<tr class="a">
<td><code>backgroundCompactionThreshold</code></td>
<td><code>0.80</code></td>
<td>Context utilization (0.0-1.0) at which background compaction starts</td></tr>
<tr class="b">
<td><code>bufferExhaustionThreshold</code></td>
<td><code>0.95</code></td>
<td>Context utilization (0.0-1.0) at which the session blocks until compaction completes</td></tr></tbody>
</table>
</section><section><a id="Accessing_the_Workspace"></a>
<h4>Accessing the Workspace</h4>
<p>When infinite sessions are enabled, you can access the workspace path:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setInfiniteSessions(new InfiniteSessionConfig().setEnabled(true))
).get();
String workspacePath = session.getWorkspacePath();
if (workspacePath != null) {
System.out.println("Session workspace: " + workspacePath);
// Access checkpoints/, plan.md, files/ subdirectories
}
</code></pre></section><section><a id="Disabling_Infinite_Sessions"></a>
<h4>Disabling Infinite Sessions</h4>
<p>For short conversations where context management isn't needed:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-5")
.setInfiniteSessions(new InfiniteSessionConfig().setEnabled(false))
).get();
// session.getWorkspacePath() will return null
</code></pre></section></section></section><section><a id="Error_Handling"></a>
<h2>Error Handling</h2>
<pre class="prettyprint"><code class="language-java">try {
var session = client.createSession().get();
session.send(new MessageOptions().setPrompt("Hello")).get();
} catch (ExecutionException ex) {
Throwable cause = ex.getCause();
System.err.println("Error: " + cause.getMessage());
}
</code></pre></section></section> </main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2026
</p>
</div>
</div>
</footer>
</body>
</html>