OpenCode SDK for Elixir

An unofficial Elixir SDK for OpenCode that mirrors the JS SDK (@opencode-ai/sdk). The API surface is generated from the OpenCode OpenAPI spec.

Installation

Add opencode to your list of dependencies in mix.exs:

def deps do
[
{:opencode, "~> 0.1.0"}
]
end

Create Server + Client

{:ok, %{client: client, server: server}} = OpenCode.create()
{:ok, health} = OpenCode.Generated.Operations.global_health(client)
OpenCode.close(%{server: server})

Options

OpenCode.create/1 forwards options to OpenCode.create_server/1.

Client Only

client = OpenCode.create_client(base_url: "http://localhost:4096")
{:ok, projects} = OpenCode.Generated.Operations.project_list(client)

Client Options

TUI

{:ok, tui} = OpenCode.create_tui(project: "/path/to/project")
OpenCode.Tui.close(tui)

Events

{:ok, %{stream: stream}} = OpenCode.Generated.Operations.event_subscribe(client)
Enum.each(stream, fn event ->
IO.inspect(event)
end)

Types

All OpenAPI types are generated under OpenCode.Generated.*.

# Example type module
OpenCode.Generated.Session

Regenerating

The OpenAPI spec lives at priv/opencode_openapi.json. To regenerate the client:

mix opencode.gen.client --spec priv/opencode_openapi.json

Note

This is not affiliated with or built by the OpenCode team.