-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdocumentation.html
More file actions
331 lines (300 loc) · 14.4 KB
/
Copy pathdocumentation.html
File metadata and controls
331 lines (300 loc) · 14.4 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
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 2.0.0 from target/filtered-site/markdown/documentation.md at 2026-01-27
| Rendered using Apache Maven Fluido Skin 2.1.0
-->
<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" />
<title>Copilot SDK for Java - Documentation – GitHub Copilot Community SDK :: Java</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-2.1.0.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.1.0.min.js"></script>
<style>.github-fork-ribbon:before { background-color: gray; }</style>
</head>
<body class="topBarEnabled">
<a class="github-fork-ribbon right-top" href="https://github.com/copilot-community-sdk/copilot-sdk-java" data-ribbon="Fork me on GitHub">Fork me on GitHub</a>
<header id="topbar" class="navbar navbar-fixed-top ">
<div class="navbar-inner">
<div class="container-fluid">
<a data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.html">GitHub Copilot SDK for Java
</a>
<ul class="nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">Overview <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="index.html">Introduction</a></li>
<li><a href="getting-started.html">Getting Started</a></li>
<li><a>Documentation</a></li>
<li><a href="mcp.html">MCP Servers</a></li>
<li><a href="advanced.html">Advanced Usage</a></li>
<li><a href="apidocs/index.html">API Javadoc</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">Guides <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="documentation.html#Basic_Usage">Basic Usage</a></li>
<li><a href="documentation.html#Handling_Responses">Handling Responses</a></li>
<li><a href="documentation.html#Streaming_Responses">Streaming</a></li>
<li><a href="documentation.html#Choosing_a_Model">Choosing a Model</a></li>
<li><a href="documentation.html#Session_Management">Session Management</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">Advanced <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="advanced.html#Custom_Tools">Custom Tools</a></li>
<li><a href="advanced.html#System_Messages">System Messages</a></li>
<li><a href="advanced.html#File_Attachments">File Attachments</a></li>
<li><a href="advanced.html#Bring_Your_Own_Key_.28BYOK.29">BYOK</a></li>
<li><a href="advanced.html#Infinite_Sessions">Infinite Sessions</a></li>
<li><a href="advanced.html#MCP_Servers">MCP Servers</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown">Project Documentation <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-submenu">
<a href="project-info.html">Project Information</a>
<ul class="dropdown-menu">
<li><a href="dependencies.html">Dependencies</a></li>
<li><a href="dependency-info.html">Maven Coordinates</a></li>
<li><a href="index.html">About</a></li>
<li><a href="licenses.html">Licenses</a></li>
<li><a href="plugin-management.html">Plugin Management</a></li>
<li><a href="plugins.html">Plugins</a></li>
<li><a href="scm.html">Source Code Management</a></li>
<li><a href="summary.html">Summary</a></li>
<li><a href="team.html">Team</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a href="project-reports.html">Project Reports</a>
<ul class="dropdown-menu">
<li><a href="apidocs/index.html">Javadoc</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</header>
<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-27<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 1.0.4<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><a href="getting-started.html">Getting Started</a></li>
<li class="active"><a>Documentation</a></li>
<li><a href="mcp.html">MCP Servers</a></li>
<li><a href="advanced.html">Advanced Usage</a></li>
<li><a href="apidocs/index.html">API Javadoc</a></li>
<li class="nav-header">Guides</li>
<li><a href="documentation.html#Basic_Usage">Basic Usage</a></li>
<li><a href="documentation.html#Handling_Responses">Handling Responses</a></li>
<li><a href="documentation.html#Streaming_Responses">Streaming</a></li>
<li><a href="documentation.html#Choosing_a_Model">Choosing a Model</a></li>
<li><a href="documentation.html#Session_Management">Session Management</a></li>
<li class="nav-header">Advanced</li>
<li><a href="advanced.html#Custom_Tools">Custom Tools</a></li>
<li><a href="advanced.html#System_Messages">System Messages</a></li>
<li><a href="advanced.html#File_Attachments">File Attachments</a></li>
<li><a href="advanced.html#Bring_Your_Own_Key_.28BYOK.29">BYOK</a></li>
<li><a href="advanced.html#Infinite_Sessions">Infinite Sessions</a></li>
<li><a href="advanced.html#MCP_Servers">MCP Servers</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>
<blockquote>
<p>⚠️ <strong>Disclaimer:</strong> This is an <strong>unofficial, community-driven SDK</strong> and is <strong>not supported or endorsed by GitHub</strong>. Use at your own risk.</p>
</blockquote>
<p>This guide covers common use cases for the Copilot SDK for Java. For complete API details, see the <a href="apidocs/index.html">Javadoc</a>.</p><section><a id="Table_of_Contents"></a>
<h2>Table of Contents</h2>
<ul>
<li><a href="#Basic_Usage">Basic Usage</a></li>
<li><a href="#Handling_Responses">Handling Responses</a></li>
<li><a href="#Streaming_Responses">Streaming Responses</a></li>
<li><a href="#Choosing_a_Model">Choosing a Model</a></li>
<li><a href="#Session_Management">Session Management</a></li>
</ul><hr /></section><section><a id="Basic_Usage"></a>
<h2>Basic Usage</h2>
<p>Create a client, start a session, and send a message:</p>
<pre class="prettyprint"><code class="language-java">import com.github.copilot.sdk.*;
import com.github.copilot.sdk.json.*;
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig().setModel("gpt-4.1")
).get();
var response = session.sendAndWait("Explain Java records in one sentence").get();
System.out.println(response.getData().getContent());
session.close();
}
</code></pre>
<p>The client manages the connection to the Copilot CLI. Sessions are independent conversations that can run concurrently.</p><hr /></section><section><a id="Handling_Responses"></a>
<h2>Handling Responses</h2><section><a id="Simple_Request-Response"></a>
<h3>Simple Request-Response</h3>
<p>For straightforward interactions, use <code>sendAndWait()</code>:</p>
<pre class="prettyprint"><code class="language-java">var response = session.sendAndWait("What is the capital of France?").get();
System.out.println(response.getData().getContent());
</code></pre></section><section><a id="Event-Based_Processing"></a>
<h3>Event-Based Processing</h3>
<p>For more control, subscribe to events and use <code>send()</code>:</p>
<pre class="prettyprint"><code class="language-java">var done = new CompletableFuture<Void>();
session.on(event -> {
if (event instanceof AssistantMessageEvent msg) {
System.out.println("Response: " + msg.getData().getContent());
} else if (event instanceof SessionErrorEvent err) {
System.err.println("Error: " + err.getData().getMessage());
} else if (event instanceof SessionIdleEvent) {
done.complete(null);
}
});
session.send("Tell me a joke").get();
done.get(); // Wait for completion
</code></pre></section><section><a id="Key_Event_Types"></a>
<h3>Key Event Types</h3>
<table class="table table-striped">
<thead>
<tr class="a">
<th>Event</th>
<th>Description</th></tr></thead><tbody>
<tr class="b">
<td><code>AssistantMessageEvent</code></td>
<td>Complete assistant response</td></tr>
<tr class="a">
<td><code>AssistantMessageDeltaEvent</code></td>
<td>Streaming chunk (when streaming enabled)</td></tr>
<tr class="b">
<td><code>SessionIdleEvent</code></td>
<td>Session finished processing</td></tr>
<tr class="a">
<td><code>SessionErrorEvent</code></td>
<td>An error occurred</td></tr>
<tr class="b">
<td><code>ToolExecutionStartEvent</code></td>
<td>Tool invocation started</td></tr>
<tr class="a">
<td><code>ToolExecutionCompleteEvent</code></td>
<td>Tool invocation completed</td></tr></tbody>
</table>
<p>See the <a href="apidocs/com/github/copilot/sdk/events/package-summary.html">events package Javadoc</a> for all event types.</p><hr /></section></section><section><a id="Streaming_Responses"></a>
<h2>Streaming Responses</h2>
<p>Enable streaming to receive response chunks as they're generated:</p>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig()
.setModel("gpt-4.1")
.setStreaming(true)
).get();
var done = new CompletableFuture<Void>();
session.on(event -> {
if (event instanceof AssistantMessageDeltaEvent delta) {
// Print each chunk as it arrives
System.out.print(delta.getData().getDeltaContent());
} else if (event instanceof SessionIdleEvent) {
System.out.println(); // Newline at end
done.complete(null);
}
});
session.send("Write a haiku about Java").get();
done.get();
</code></pre><hr /></section><section><a id="Choosing_a_Model"></a>
<h2>Choosing a Model</h2><section><a id="List_Available_Models"></a>
<h3>List Available Models</h3>
<p>Query available models before creating a session:</p>
<pre class="prettyprint"><code class="language-java">List<ModelInfo> models = client.listModels().get();
for (ModelInfo model : models) {
System.out.printf("%s (%s)%n", model.getId(), model.getName());
}
</code></pre></section><section><a id="Use_a_Specific_Model"></a>
<h3>Use a Specific Model</h3>
<pre class="prettyprint"><code class="language-java">var session = client.createSession(
new SessionConfig().setModel("claude-sonnet-4")
).get();
</code></pre><hr /></section></section><section><a id="Session_Management"></a>
<h2>Session Management</h2><section><a id="Multiple_Concurrent_Sessions"></a>
<h3>Multiple Concurrent Sessions</h3>
<pre class="prettyprint"><code class="language-java">var session1 = client.createSession(
new SessionConfig().setModel("gpt-4.1")
).get();
var session2 = client.createSession(
new SessionConfig().setModel("claude-sonnet-4")
).get();
// Send messages concurrently
var future1 = session1.sendAndWait("Summarize REST APIs");
var future2 = session2.sendAndWait("Summarize GraphQL");
System.out.println("GPT: " + future1.get().getData().getContent());
System.out.println("Claude: " + future2.get().getData().getContent());
</code></pre></section><section><a id="Resume_a_Previous_Session"></a>
<h3>Resume a Previous Session</h3>
<pre class="prettyprint"><code class="language-java">// Get the last session ID
String lastSessionId = client.getLastSessionId().get();
// Or list all sessions
List<SessionMetadata> sessions = client.listSessions().get();
// Resume a session
var session = client.resumeSession(lastSessionId).get();
</code></pre></section><section><a id="Clean_Up_Sessions"></a>
<h3>Clean Up Sessions</h3>
<pre class="prettyprint"><code class="language-java">// Delete a specific session
client.deleteSession(sessionId).get();
</code></pre><hr /></section></section><section><a id="Next_Steps"></a>
<h2>Next Steps</h2>
<ul>
<li>📖 <strong><a href="advanced.html">Advanced Usage</a></strong> - Tools, BYOK, MCP Servers, System Messages, Infinite Sessions</li>
<li>📖 <strong><a href="mcp.html">MCP Servers</a></strong> - Integrate external tools via Model Context Protocol</li>
<li>📖 <strong><a href="apidocs/index.html">API Javadoc</a></strong> - Complete API reference</li>
</ul></section></section> </main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2026
</p>
</div>
</div>
</footer>
</body>
</html>