Skip to content
Conduit

skill

opencode-api

A Dart package that wraps the opencode.ai API using retrofit for type-safe HTTP requests.

cdavis-code/opencode_apicommunitylistedunreviewed

Set up

Skills are installed by placing their folder where your agent loads skills.

The download comes from github.com/cdavis-code/opencode_api itself, not from our server, so what you get is exactly what its author published.

Install instructions come from the README

Skills do not use an MCP config. Follow the steps in the README below.

README

synced Oct 26, 2026

opencode_api

A Dart package that wraps the opencode.ai API using retrofit for type-safe HTTP requests.

Table of Contents

Quick Start

import 'package:opencode_api/opencode_api.dart';

void main() async {
  // Connect to the opencode server
  final opencode = await Opencode.connect(
    username: 'opencode',
    password: 'your-password',
    baseUrl: 'http://localhost:4096'
  );

  // Use service groups to access API endpoints
  final health = await opencode.global.getHealth();
  print('Server healthy: ${health.healthy}');
  
  // List sessions
  final sessions = await opencode.session.getSessions();
  print('Found ${sessions.length} sessions');
}

Features

  • Type-safe API client - Uses retrofit for compile-time API contracts
  • Service-oriented architecture - Organized API endpoints into logical service groups
  • Comprehensive endpoints - Covers all opencode.ai API endpoints
  • Secure error handling - Custom exceptions with user-friendly messages, no implementation leaks
  • Built-in logging - Uses logger package with platform-aware conditional imports
  • Easy authentication - HTTP Basic Auth support

Configuration

VariableDescriptionDefault
baseUrlServer URLhttp://localhost:4096
usernameAuth usernameopencode
passwordAuth password(required)

API Services

The Opencode object provides access to the following service groups:

Global

MethodDescriptionResponse
getHealth()Get server health and versionHealthResponse
getGlobalEvents()Get global events (SSE stream)Stream<String>

Project

MethodDescriptionResponse
getProjects()List all projectsList<Project>
getCurrentProject()Get the current projectProject

Path & VCS

MethodDescriptionResponse
getPath()Get the current pathPathResponse
getVcs()Get VCS info for the current projectVcsResponse

Instance

MethodDescriptionResponse
disposeInstance()Dispose the current instancebool

Config

MethodDescriptionResponse
getConfig()Get config infoConfigResponse
updateConfig(body)Update configConfigResponse
getConfigProviders()List providers and default modelsConfigProvidersResponse

Provider

MethodDescriptionResponse
getProviders()List all providersProviderListResponse
getProviderAuth()Get provider authentication methodsProviderAuthMethodsResponse
authorizeProvider(id, body)Authorize a provider using OAuthProviderAuthAuthorization
providerOAuthCallback(id, body)Handle OAuth callback for a providerbool

Session

MethodDescriptionResponse
getSessions()List all sessionsList<Session>
createSession(body)Create a new sessionSession
getSessionStatus()Get session status for all sessionsMap<String, SessionStatus>
getSession(id)Get session detailsSession
deleteSession(id)Delete a session and all its databool
updateSession(id, body)Update session propertiesSession
getSessionChildren(id)Get a session's child sessionsList<Session>
getSessionTodo(id)Get the todo list for a sessionList<Todo>
initSession(id, body)Analyze app and create AGENTS.mdbool
forkSession(id, body)Fork an existing session at a messageSession
abortSession(id)Abort a running sessionbool
shareSession(id)Share a sessionSession
unshareSession(id)Unshare a sessionSession
getSessionDiff(id, messageID?)Get the diff for this sessionList<FileDiff>
summarizeSession(id, body)Summarize the sessionbool
revertMessage(id, body)Revert a messagebool
unrevertMessages(id)Restore all reverted messagesbool
respondToPermissionRequest(id, permissionID, body)Respond to a permission requestbool

Messages (via Session Service)

MethodDescriptionResponse
getMessages(id, limit?)List messages in a sessionList<MessageWithParts>
sendMessage(id, body)Send a message and wait for responseMessageWithParts
getMessage(id, messageID)Get message detailsMessageWithParts
sendMessageAsync(id, body)Send a message asynchronously (no wait)void
executeCommand(id, body)Execute a slash commandMessageWithParts
runShell(id, body)Run a shell commandMessageWithParts

Commands

MethodDescriptionResponse
getCommands()List all commandsList<Command>

Files

MethodDescriptionResponse
findInFiles(pattern)Search for text in filesList<FindResult>
findFiles(query)Find files and directories by nameList<String>
findSymbols(query)Find workspace symbolsList<Symbol>
listFiles(path?)List files and directoriesList<FileNodeResponse>
getFileContent(path)Read a fileFileContentResponse
getFileStatus()Get status for tracked filesList<FileStatus>

Tools (Experimental)

MethodDescriptionResponse
getToolIds()List all tool IDsToolIDs
getTools(provider?, model?)List tools with JSON schemas for a modelToolList

LSP, Formatters & MCP

MethodDescriptionResponse
getLspStatus()Get LSP server statusList<LSPStatus>
getFormatterStatus()Get formatter statusList<FormatterStatus>
getMcpStatus()Get MCP server statusMap<String, MCPStatus>
addMcpServer(body)Add MCP server dynamicallyMCPStatus

Agents

MethodDescriptionResponse
getAgents()List all available agentsList<Agent>

Logging

MethodDescriptionResponse
writeLog(body)Write log entrybool

TUI

MethodDescriptionResponse
tuiAppendPrompt(body)Append text to the promptbool
tuiOpenHelp()Open the help dialogbool
tuiOpenSessions()Open the session selectorbool
tuiOpenThemes()Open the theme selectorbool
tuiOpenModels()Open the model selectorbool
tuiSubmitPrompt()Submit the current promptbool
tuiClearPrompt()Clear the promptbool
tuiExecuteCommand(body)Execute a commandbool
tuiShowToast(body)Show toastbool
tuiControlNext()Wait for the next control requestControlRequest
tuiControlResponse(body)Respond to a control requestbool

Auth

MethodDescriptionResponse
setAuth(id, body)Set authentication credentialsbool

Events

MethodDescriptionResponse
getEvents()Get events (SSE stream)Stream<String>

Migration from OpencodeClient

The old OpencodeClient is deprecated but still available for backward compatibility. Here's how to migrate:

Old API (Deprecated)

final dio = OpencodeClient.createDio(username: 'user', password: 'pass');
final client = OpencodeClient(dio);
final health = await client.getHealth();

New API (Recommended)

final opencode = await Opencode.connect(
  username: 'user', 
  password: 'pass'
);
final health = await opencode.global.getHealth();

Documentation

Error Handling

The package provides user-friendly error messages without exposing implementation details:

try {
  final sessions = await opencode.session.getSessions();
} catch (e) {
  if (e is OpencodeException) {
    print(e.userMessage); // Safe for users
  }
}

Running the Generator

After changes to API definitions:

dart run build_runner build --delete-conflicting-outputs

Contributors

Thanks to all the contributors who have helped make this package better!

Support

If you find this package helpful, consider supporting its development:

Buy Me a Coffee

License

MIT - See LICENSE

↑↓ navigate openesc close