sdk: simplify getting started with single createOpencode function

Makes it easier for developers to get started by providing a single function that creates both server and client, removing the need to manually coordinate separate server and client creation
This commit is contained in:
Dax Raad
2025-10-05 07:00:29 -04:00
parent 71a7e8ef36
commit f3c2d1b6c2
3 changed files with 47 additions and 34 deletions

View File

@@ -25,17 +25,16 @@ npm install @opencode-ai/sdk
## Create client
Create a client instance to connect to your server:
Create an instance of opencode:
```javascript
import { createOpencodeClient } from "@opencode-ai/sdk"
import { createOpencode } from "@opencode-ai/sdk"
const client = createOpencodeClient({
baseUrl: "http://localhost:4096",
responseStyle: "data",
})
const { client } = await createOpencode()
```
This starts both a server and a client
#### Options
| Option | Type | Description | Default |
@@ -48,29 +47,14 @@ const client = createOpencodeClient({
---
## Start server
## Config
You can also programmatically start an opencode server:
You can pass a configuration object to customize behavior. The instance still picks up your `opencode.json`, but you can override or add configuration inline:
```javascript
import { createOpencodeServer } from "@opencode-ai/sdk"
import { createOpencode } from "@opencode-ai/sdk"
const server = await createOpencodeServer({
hostname: "127.0.0.1",
port: 4096,
})
console.log(`Server running at ${server.url}`)
server.close()
```
You can pass a configuration object to customize server behavior. The server still picks up your `opencode.json`, but you can override or add configuration inline:
```javascript
import { createOpencodeServer } from "@opencode-ai/sdk"
const server = await createOpencodeServer({
const opencode = await createOpencode({
hostname: "127.0.0.1",
port: 4096,
config: {
@@ -78,9 +62,21 @@ const server = await createOpencodeServer({
},
})
console.log(`Server running at ${server.url}`)
console.log(`Server running at ${opencode.server.url}`)
server.close()
opencode.server.close()
```
## Client only
If you aready have a running instance of opencode, you can create a client instance to connect to it:
```javascript
import { createOpencodeClient } from "@opencode-ai/sdk"
const client = createOpencodeClient({
baseUrl: "http://localhost:4096",
})
```
#### Options