| 1 | # OpenCode Workerd SDK |
| 2 | |
| 3 | This example runs the OpenCode Workerd SDK in a Durable Object. The Durable |
| 4 | Object storage holds the SDK state, so a session survives a restart. The example |
| 5 | creates a session, sends a prompt, waits for the run to complete, and returns |
| 6 | the assistant reply. |
| 7 | |
| 8 | The example needs no credentials. The SDK resolves a free model from its own |
| 9 | provider registry, and it reports the model that answered. |
| 10 | |
| 11 | Install the example dependencies with `npm ci`, then start it: |
| 12 | |
| 13 | ```sh |
| 14 | celld dev . |
| 15 | curl http://127.0.0.1:9876/ |
| 16 | ``` |
| 17 | |
| 18 | A successful response contains the reply and the model that produced it: |
| 19 | |
| 20 | ```json |
| 21 | { |
| 22 | "ok": true, |
| 23 | "model": { |
| 24 | "providerID": "opencode", |
| 25 | "modelID": "nemotron-3.5-lightning-free" |
| 26 | }, |
| 27 | "prompt": "hello world", |
| 28 | "reply": "Hello! How can I help you today?", |
| 29 | "checks": [{ "name": "model.default", "ok": true, "ms": 12 }] |
| 30 | } |
| 31 | ``` |
| 32 | |
| 33 | The response has status 502 when the run completes but no assistant reply |
| 34 | arrives, and status 500 when an SDK call fails. Therefore a broken model path |
| 35 | fails the probe instead of passing it. |