opencode-sdk-python/api.md
Alberto Garcia Illera 301f5cec71
fix: correct session.chat() return type to match server response
The OpenCode server's POST /session/{id}/message endpoint returns a
wrapper object with 'info' (the assistant message) and 'parts' (the
message parts):

    {"info": AssistantMessage, "parts": Part[]}

The SDK was casting this response to bare AssistantMessage, which
caused Pydantic to silently produce a hollow object where all fields
(id, role, tokens, etc.) were None.

This commit:
- Adds SessionChatResponse type with 'info: Message' and 'parts: List[Part]'
  fields matching the actual server response shape
- Updates both sync and async chat() to return SessionChatResponse
- Exports the new type from types/__init__.py
- Updates api.md documentation
2026-02-21 12:37:30 -08:00

7.1 KiB

Shared Types

from opencode_ai.types import MessageAbortedError, ProviderAuthError, UnknownError

Event

Types:

from opencode_ai.types import EventListResponse

Methods:

App

Types:

from opencode_ai.types import (
    App,
    Mode,
    Model,
    Provider,
    AppInitResponse,
    AppLogResponse,
    AppModesResponse,
    AppProvidersResponse,
)

Methods:

Find

Types:

from opencode_ai.types import Symbol, FindFilesResponse, FindSymbolsResponse, FindTextResponse

Methods:

File

Types:

from opencode_ai.types import File, FileReadResponse, FileStatusResponse

Methods:

Config

Types:

from opencode_ai.types import Config, KeybindsConfig, McpLocalConfig, McpRemoteConfig, ModeConfig

Methods:

Session

Types:

from opencode_ai.types import (
    AssistantMessage,
    FilePart,
    FilePartInput,
    FilePartSource,
    FilePartSourceText,
    FileSource,
    Message,
    Part,
    Session,
    SnapshotPart,
    StepFinishPart,
    StepStartPart,
    SymbolSource,
    TextPart,
    TextPartInput,
    ToolPart,
    ToolStateCompleted,
    ToolStateError,
    ToolStatePending,
    ToolStateRunning,
    UserMessage,
    SessionListResponse,
    SessionDeleteResponse,
    SessionAbortResponse,
    SessionInitResponse,
    SessionMessagesResponse,
    SessionSummarizeResponse,
)

Methods:

Tui

Types:

from opencode_ai.types import TuiAppendPromptResponse, TuiOpenHelpResponse

Methods: