Skip to content

Repository files navigation

Opencode Python SDK 1.15.5

A Python SDK for the opencode REST API, pinned to opencode server version 1.15.5 and generated by liblab from the current OpenAPI specification.

Why this fork?

The official Python SDK at anomalyco/opencode-sdk-python (PyPI: opencode-ai) has been stuck on v0.1.0-alpha.36 since 2025-08-27 and only exposes a small slice of the early API surface (/session, /session/{id}/message, /file, /find, /app, /event).

It does not cover the surface a modern opencode server (1.15+) actually exposes — the table below shows what's missing from anomalyco but present here:

Endpoint / event anomalyco (opencode-ai) this SDK (opencode-api)
GET /session/status
GET /session/{id}/todo
GET /session/{id}/diff
GET /question + reply
GET /permission + reply
POST /session/{id}/prompt_async
Bus events: session.status, session.idle, todo.updated, session.diff, question.asked, permission.asked, etc.

If you need anything beyond the alpha endpoint set, use this SDK.

Versions

  • SDK version: 1.15.5 (tracks opencode server release)
  • Targets opencode server: 1.15.5
  • Distribution name on import: opencode_api (PyPI dist name: opencode-api)

Distinct from opencode-ai (anomalyco) — pick one or the other, not both.

This SDK was generated by liblab

About the API

opencode api

Table of Contents

Setup & Configuration

Supported Language Versions

This SDK is compatible with the following versions: Python >= 3.9

Installation

This SDK is not currently published on PyPI — install directly from this repository. Pin to the tag that matches your opencode server version.

Using uv (recommended)

uv add "opencode-api @ git+https://github.com/that-ambuj/opencode-python-sdk.git@v1.15.5"

Or for a one-off install into the current environment:

uv pip install "git+https://github.com/that-ambuj/opencode-python-sdk.git@v1.15.5"

Using pip3

pip3 install "git+https://github.com/that-ambuj/opencode-python-sdk.git@v1.15.5"

Pinning in pyproject.toml

dependencies = [
  "opencode-api @ git+https://github.com/that-ambuj/opencode-python-sdk.git@v1.15.5",
]

Pinning in requirements.txt

opencode-api @ git+https://github.com/that-ambuj/opencode-python-sdk.git@v1.15.5

Latest unstable main

uv pip install "git+https://github.com/that-ambuj/opencode-python-sdk.git"
# or
pip3 install "git+https://github.com/that-ambuj/opencode-python-sdk.git"

Authentication

Access Token Authentication

The Opencode API uses an Access Token for authentication.

This token must be provided to authenticate your requests to the API.

Setting the Access Token

When you initialize the SDK, you can set the access token as follows:

Opencode(
    access_token="YOUR_ACCESS_TOKEN",
    timeout=10000
)

If you need to set or update the access token after initializing the SDK, you can use:

sdk.set_access_token("YOUR_ACCESS_TOKEN")

Setting a Custom Timeout

You can set a custom timeout for the SDK's HTTP requests as follows:

from opencode_api import Opencode

sdk = Opencode(timeout=10000)

Sample Usage

Below is a comprehensive example demonstrating how to authenticate and call a simple endpoint:

from opencode_api import Opencode

sdk = Opencode(
    access_token="YOUR_ACCESS_TOKEN",
    timeout=10000
)

result = sdk.global_.global_health()

print(result)

Async Usage

The SDK includes an Async Client for making asynchronous API requests. This is useful for applications that need non-blocking operations, like web servers or apps with a graphical user interface.

import asyncio
from opencode_api import OpencodeAsync

sdk = OpencodeAsync(
    access_token="YOUR_ACCESS_TOKEN",
    timeout=10000
)


async def main():
  result = await sdk.global_.global_health()
  print(result)

asyncio.run(main())

Services

The SDK provides various services to interact with the API.

Below is a list of all available services with links to their detailed documentation:
Name
ControlService
GlobalService
EventService
ConfigService
ExperimentalService
FileService
InstanceService
McpService
ProjectService
PtyService
QuestionService
PermissionService
ProviderService
SessionService
SyncService
V2Service
V2MessagesService
V2ModelsService
V2ProvidersService
TuiService
WorkspaceService

Models

The SDK includes several models that represent the data structures used in API requests and responses. These models help in organizing and managing the data efficiently.

Below is a list of all available models with links to their detailed documentation:
Name Description
AppLogRequest
GlobalHealthOkResponse Health information
GlobalEvent
Config
GlobalUpgradeRequest
ConfigProvidersOkResponse List of providers
ConsoleState
ExperimentalConsoleListOrgsOkResponse Switchable Console orgs
ExperimentalConsoleSwitchOrgRequest
ToolListItem
WorktreeCreateInput
Worktree
WorktreeRemoveInput
WorktreeResetInput
GlobalSession
McpResource
FindTextOkResponse
Dirs
FindFilesType
Symbol
FileNode
FileContent
File
Path
VcsInfo
VcsFileStatus
VcsFileDiff
VcsDiffMode
VcsApplyRequest
VcsApplyOkResponse VCS patch applied
Command
Agent
AppSkillsOkResponse
LspStatus
FormatterStatus
McpAddRequest
McpAuthStartOkResponse OAuth flow started
McpAuthRemoveOkResponse OAuth credentials removed
McpAuthCallbackRequest
Project
ProjectUpdateRequest
PtyShellsOkResponse
Pty
PtyCreateRequest
PtyUpdateRequest
PtyConnectTokenOkResponse WebSocket connect token
QuestionRequest
QuestionReplyRequest
PermissionRequest
PermissionReplyRequest
ProviderListOkResponse List of providers
ProviderAuthMethod
ProviderOauthAuthorizeRequest
ProviderAuthAuthorization
ProviderOauthCallbackRequest
Session
Scope
SessionCreateRequest
SessionUpdateRequest
Todo
SnapshotFileDiff
SessionMessagesOkResponse
SessionPromptRequest
SessionPromptOkResponse
SessionMessageOkResponse Message
SessionForkRequest
SessionInitRequest
SessionSummarizeRequest
SessionPromptAsyncRequest
SessionCommandRequest
SessionCommandOkResponse
SessionShellRequest
SessionShellOkResponse Created message
SessionRevertRequest
PermissionRespondRequest
SyncReplayRequest
SyncReplayOkResponse Replayed sync events
SyncStealRequest
SyncStealOkResponse Session stolen into workspace
SyncHistoryListOkResponse
V2SessionsResponse
V2SessionListOrder
V2SessionPromptRequest
V2SessionMessagesResponse
V2SessionMessagesOrder
ModelV2Info
V2ModelListLocation
ProviderV2Info
V2ProviderListLocation
V2ProviderGetLocation
TuiAppendPromptRequest
TuiExecuteCommandRequest
TuiShowToastRequest
TuiSelectSessionRequest
TuiControlNextOkResponse Next TUI request
ExperimentalWorkspaceAdapterListOkResponse
Workspace
ExperimentalWorkspaceCreateRequest
ExperimentalWorkspaceStatusOkResponse
ExperimentalWorkspaceWarpRequest
OAuth
ApiAuth
WellKnownAuth
EventServerInstanceDisposed
EventPermissionAsked
EventPermissionReplied
EventLspClientDiagnostics
EventLspUpdated
EventMessagePartDelta
EventSessionDiff
EventSessionError
Payload_9
Payload_10
Payload_11
Payload_12
EventInstallationUpdated
EventInstallationUpdateAvailable
EventMcpToolsChanged
EventMcpBrowserOpenFailed
EventCommandExecuted
EventProjectUpdated
EventWorktreeReady
EventWorktreeFailed
EventFileEdited
EventFileWatcherUpdated
EventVcsBranchUpdated
EventQuestionAsked
EventQuestionReplied
EventQuestionRejected
EventTodoUpdated
EventSessionStatus
EventSessionIdle
EventSessionCompacted
EventWorkspaceReady
EventWorkspaceFailed
EventWorkspaceStatus
EventPtyCreated
EventPtyUpdated
EventPtyExited
EventPtyDeleted
EventMessageUpdated
EventMessageRemoved
EventMessagePartUpdated
EventMessagePartRemoved
EventSessionCreated
EventSessionUpdated
EventSessionDeleted
EventSessionNextAgentSwitched
EventSessionNextModelSwitched
EventSessionNextPrompted
EventSessionNextSynthetic
EventSessionNextShellStarted
EventSessionNextShellEnded
EventSessionNextStepStarted
EventSessionNextStepEnded
EventSessionNextStepFailed
EventSessionNextTextStarted
EventSessionNextTextDelta
EventSessionNextTextEnded
EventSessionNextReasoningStarted
EventSessionNextReasoningDelta
EventSessionNextReasoningEnded
EventSessionNextToolInputStarted
EventSessionNextToolInputDelta
EventSessionNextToolInputEnded
EventSessionNextToolCalled
EventSessionNextToolProgress
EventSessionNextToolSuccess
EventSessionNextToolFailed
EventSessionNextRetried
EventSessionNextCompactionStarted
EventSessionNextCompactionDelta
EventSessionNextCompactionEnded
EventServerConnected
EventGlobalDisposed
EventCatalogModelUpdated
SyncEventMessageUpdated
SyncEventMessageRemoved
SyncEventMessagePartUpdated
SyncEventMessagePartRemoved
SyncEventSessionCreated
SyncEventSessionUpdated
SyncEventSessionDeleted
SyncEventSessionNextAgentSwitched
SyncEventSessionNextModelSwitched
SyncEventSessionNextPrompted
SyncEventSessionNextSynthetic
SyncEventSessionNextShellStarted
SyncEventSessionNextShellEnded
SyncEventSessionNextStepStarted
SyncEventSessionNextStepEnded
SyncEventSessionNextStepFailed
SyncEventSessionNextTextStarted
SyncEventSessionNextTextDelta
SyncEventSessionNextTextEnded
SyncEventSessionNextReasoningStarted
SyncEventSessionNextReasoningDelta
SyncEventSessionNextReasoningEnded
SyncEventSessionNextToolInputStarted
SyncEventSessionNextToolInputDelta
SyncEventSessionNextToolInputEnded
SyncEventSessionNextToolCalled
SyncEventSessionNextToolProgress
SyncEventSessionNextToolSuccess
SyncEventSessionNextToolFailed
SyncEventSessionNextRetried
SyncEventSessionNextCompactionStarted
SyncEventSessionNextCompactionDelta
SyncEventSessionNextCompactionEnded
ProviderAuthError
UnknownError
MessageOutputLengthError
MessageAbortedError
StructuredOutputError
ContextOverflowError
ApiError
QuestionInfo
QuestionTool
QuestionOption
QuestionReplied
QuestionRejected
UserMessage
AssistantMessage
OutputFormatText
OutputFormatJsonSchema
TextPart
SubtaskPart
ReasoningPart
FilePart
ToolPart
StepStartPart
StepFinishPart
SnapshotPart
PatchPart
AgentPart
RetryPart
CompactionPart
FileSource
SymbolSource
ResourceSource
FilePartSourceText
Range
ToolStatePending
ToolStateRunning
ToolStateCompleted
ToolStateError
PermissionRule
PermissionAction
Prompt
PromptFileAttachment
PromptAgentAttachment
PromptReferenceAttachment
PromptSource
SessionErrorUnknown
ToolTextContent
ToolFileContent
SessionNextRetryError
LogLevel Log level
ServerConfig Server configuration for opencode serve and web commands
ProviderConfig
LayoutConfig @deprecated Always uses stretch layout.
AttachmentConfig
AgentConfig
PermissionActionConfig
McpLocalConfig
McpRemoteConfig
McpOAuthConfig
ImageAttachmentConfig
EventTuiToastShow1
Provider
Model
ProjectSummary
McpStatusConnected
McpStatusDisabled
McpStatusFailed
McpStatusNeedsAuth
McpStatusNeedsClientRegistration
TextPartInput
FilePartInput
AgentPartInput
SubtaskPartInput
SessionInfo
SessionDelivery
SessionMessageAgentSwitched
SessionMessageModelSwitched
SessionMessageUser
SessionMessageSynthetic
SessionMessageShell
SessionMessageAssistant
SessionMessageCompaction
SessionMessageAssistantText
SessionMessageAssistantReasoning
SessionMessageAssistantTool
SessionMessageToolStatePending
SessionMessageToolStateRunning
SessionMessageToolStateCompleted
SessionMessageToolStateError
TuiPublishRequest_1
TuiPublishRequest_2
TuiPublishRequest_3
TuiPublishRequest_4
BadRequestError
EffectHttpApiErrorInternalServerError
WorktreeError
VcsApplyError
McpUnsupportedOAuthError
NotFoundError
EffectHttpApiErrorForbidden
ProviderAuthError1
WorkspaceWarpError

Using Union Types

Union types allow you to specify that a variable can have more than one type. This is particularly useful when a function can accept multiple types of inputs. The Union type hint is used for this purpose.

Example Function with Union Types

You can call service method with an instance of TypeA, TypeB, or a dictionary that can be converted to an instance of either type.

# Model Definition
ParamType = Union[TypeA, TypeB]

# Service Method
def service_method(param: ParamType):
...

## Usage
type_a = TypeA(key="value")
type_b = TypeB(key="value")

sdk.service.service_method(type_a)
sdk.service.service_method(type_b)
sdk.service.service_method({"key": "value"})

You cannot create an instance of a Union type itself. Instead, pass an instance of one of the types in the Union, or a dictionary that can be converted to one of those types.

About

Python SDK for opencode REST API. Pinned to opencode server 1.15.5. Generated by liblab from the OpenAPI spec.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages