Copilot SDK for Java
⚠️ Disclaimer: This is an unofficial, community-driven SDK and is not supported or endorsed by GitHub. Use at your own risk.
Welcome to the documentation for the Copilot SDK for Java — a Java SDK for programmatic control of GitHub Copilot CLI, enabling you to build AI-powered applications and agentic workflows.
Getting Started
Requirements
- Java 17 or later
- GitHub Copilot CLI installed and in PATH (or provide custom
cliPath)
Installation
Add the dependency to your project:
Maven:
<dependency>
<groupId>io.github.copilot-community-sdk</groupId>
<artifactId>copilot-sdk</artifactId>
<version>1.0.5-SNAPSHOT</version>
</dependency>
Gradle:
implementation 'io.github.copilot-community-sdk:copilot-sdk:1.0.5-SNAPSHOT'
Quick Example
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.CompletableFuture;
public class Example {
public static void main(String[] args) throws Exception {
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(
new SessionConfig().setModel("claude-sonnet-4.5")
).get();
var done = new CompletableFuture<Void>();
session.on(evt -> {
if (evt instanceof AssistantMessageEvent msg) {
System.out.println(msg.getData().getContent());
} else if (evt instanceof SessionIdleEvent) {
done.complete(null);
}
});
session.send(new MessageOptions().setPrompt("What is 2+2?")).get();
done.get();
}
}
}
Documentation
| Document | Description |
|---|---|
| Documentation | Basic usage, streaming, handling responses, and session management |
| Advanced Usage | Tools, BYOK, MCP servers, infinite sessions, and more |
| MCP Servers | Integrating Model Context Protocol servers |
| Javadoc | Generated API documentation |
Try it with JBang
You can quickly try the SDK without setting up a full project using JBang:
# Install JBang (if not already installed)
# macOS: brew install jbang
# Linux/Windows: curl -Ls https://sh.jbang.dev | bash -s - app setup
# Create a simple script
cat > hello-copilot.java << 'EOF'
//DEPS io.github.copilot-community-sdk:copilot-sdk:1.0.5-SNAPSHOT
import com.github.copilot.sdk.*;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;
import java.util.concurrent.CompletableFuture;
class hello {
public static void main(String[] args) throws Exception {
try (var client = new CopilotClient()) {
client.start().get();
var session = client.createSession(new SessionConfig()).get();
var done = new CompletableFuture<Void>();
session.on(evt -> {
if (evt instanceof AssistantMessageEvent msg) {
System.out.print(msg.getData().getContent());
} else if (evt instanceof SessionIdleEvent) {
done.complete(null);
}
});
session.send(new MessageOptions().setPrompt("Say hello!")).get();
done.get();
}
}
}
EOF
# Run it
jbang hello-copilot.java
