Skip to content

OpenCode Go Kit

A Go API for interacting with the OpenCode API.

Requirements

  • Go: 1.26.4+ (to compile, run tests, and generate client bindings)

Installation

To integrate the OpenCode Go Kit into an existing Go project, run:

go get github.com/dakolli/opencode-go-kit

Quick Start Example

Here is a simple example demonstrating how to configure the client, instantiate the API, and call a typed API method (e.g., AppAgents) returning Go types:

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/dakolli/opencode-go-kit/pkg/api"
    "github.com/dakolli/opencode-go-kit/pkg/client"
)

func main() {
    ctx := context.Background()

    // 1. Create client configuration (either pass values explicitly or let them fallback to environment variables)
    config, err := api.NewClientCFG(
        "http://localhost:4096", // OpenCode Server URL
        "opencode",              // Username
        "pass1",                 // Password
    )
    if err != nil {
        log.Fatalf("failed to initialize configuration: %v", err)
    }

    // 2. Instantiate the clean, typed API wrapper
    opencodeAPI, err := api.NewAPI(config)
    if err != nil {
        log.Fatalf("failed to initialize API: %v", err)
    }

    // 3. Invoke a typed API method with full parameter support
    // Our wrapper automatically unwraps sum-type interfaces into clean, native slice types
    agents, err := opencodeAPI.AppAgents(ctx, client.AppAgentsParams{})
    if err != nil {
        log.Fatalf("API invocation failed: %v", err)
    }

    fmt.Printf("Retrieved %d AI agents from OpenCode:\n", len(agents))
    for _, agent := range agents {
        fmt.Printf(" - %s: %s\n", agent.Name, agent.Description.Value)
    }
}

API Endpoint Coverage

API Coverage

We have wrapped 83 out of 83 (100.00%) OpenAPI client methods in our clean, typed API wrapper layer.

Covered Endpoints

- [x] AppAgents - [x] SessionDiff
- [x] AppSkills - [x] SessionList
- [x] CommandList - [x] SessionShare
- [x] ConfigProviders - [x] SessionUnshare
- [x] ExperimentalCapabilitiesGet - [x] SyncStart
- [x] ExperimentalConsoleGet - [x] TuiClearPrompt
- [x] ExperimentalConsoleListOrgs - [x] TuiControlNext
- [x] ExperimentalConsoleSwitchOrg - [x] TuiControlResponse
- [x] ExperimentalProjectCopyGenerateName - [x] TuiOpenHelp
- [x] ExperimentalResourceList - [x] TuiOpenModels
- [x] ExperimentalSessionList - [x] TuiOpenSessions
- [x] ExperimentalWorkspaceAdapterList - [x] TuiOpenThemes
- [x] ExperimentalWorkspaceStatus - [x] TuiShowToast
- [x] ExperimentalWorkspaceSyncList - [x] TuiSubmitPrompt
- [x] FileList - [x] V2CommandList
- [x] FileRead - [x] V2CredentialRemove
- [x] FileStatus - [x] V2CredentialUpdate
- [x] FindFiles - [x] V2FsFind
- [x] FindSymbols - [x] V2FsList
- [x] FindText - [x] V2FsRead
- [x] FormatterStatus - [x] V2HealthGet
- [x] GlobalDispose - [x] V2IntegrationAttemptCancel
- [x] GlobalHealth - [x] V2LocationGet
- [x] InstanceDispose - [x] V2PermissionRequestList
- [x] LspStatus - [x] V2PermissionSavedList
- [x] McpAuthRemove - [x] V2PermissionSavedRemove
- [x] McpConnect - [x] V2PtyConnect
- [x] McpDisconnect - [x] V2PtyConnectToken
- [x] PathGet - [x] V2PtyCreate
- [x] PermissionList - [x] V2PtyGet
- [x] ProjectCurrent - [x] V2PtyList
- [x] ProjectDirectories - [x] V2PtyRemove
- [x] ProjectInitGit - [x] V2PtyUpdate
- [x] ProjectList - [x] V2QuestionRequestList
- [x] ProviderList - [x] V2SessionActive
- [x] PtyConnect - [x] V2SessionCreate
- [x] PtyConnectToken - [x] V2SkillList
- [x] PtyGet - [x] VcsDiff
- [x] PtyList - [x] VcsDiffRaw
- [x] PtyRemove - [x] VcsGet
- [x] PtyShells - [x] VcsStatus
- [x] QuestionList