Skip to content

Inquiry: Programmatic access or Node.js SDK for OpenCode #4028

Closed

Description

@i18nsite

Hello, I am looking for a way to call the OpenCode agent programmatically from a Node.js environment.

Is there an existing Node.js SDK, or an API, that allows for this?

My goal is to integrate OpenCode's functionality into other automated workflows, and having an SDK or API would be very helpful for this purpose.

Activity

  1. github-actions commented on Nov 7, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. sandipwane commented on Nov 7, 2025

    @sandipwane
    Contributor

    Hey @i18nsite,

    Yes, OpenCode has a Node.js SDK for programmatic access.

    Install:

    npm install @opencode-ai/sdk

    Source: https://github.com/sst/opencode/tree/dev/packages/sdk/js

    Docs: https://opencode.ai/docs/sdk/

    Quick start:

    import { createOpencodeClient, createOpencodeServer } from "@opencode-ai/sdk"
    
    // Start server
    const server = await createOpencodeServer()
    const client = createOpencodeClient({ baseUrl: server.url })
    
    // Create session & send prompt
    const session = await client.session.create()
    await client.session.prompt({
      path: { id: session.data.id },
      body: {
        parts: [
          { type: "text", text: "Your prompt here" }
        ]
      }
    })

    SDK handles sessions, file ops, streaming responses - everything needed for automation.

    Note: Last time I used @opencode-ai/sdk, the npm package wasn't up to date. I ended up using the SDK directly from the monorepo - cloned sst/opencode and installed the JS SDK folder directly into my project using bun. Check the npm version first, but if you need latest features, the monorepo approach works well.

    Let me know if you need help with specific use cases.

  3. self-assigned this
    on Nov 7, 2025
  4. rekram1-node commented on Nov 7, 2025

    @rekram1-node
    Contributor

    The sdk should be up to date now

    and thank u @sandipwane for being so helpful

  5. mrlubos commented on Jan 13, 2026

    @mrlubos
    Contributor

    @i18nsite is your issue solved now?

  6. ashish16052 commented on Jul 9, 2026

    @ashish16052

    The current mental model that has worked for me is:

    • OpenCode server/API/SDK = how to talk to OpenCode programmatically.
    • Runtime/orchestration layer = how to run OpenCode safely inside another app.

    For a single automation script, the server/API is enough. For a backend product, the hard parts become: which OpenCode process owns the session, how to isolate workspace/history/config per user, how to stream progress back to the app, and how to clean up or restart stuck servers.

    I’m working on this from the Python side here:
    https://github.com/ashish16052/opencode-runtime

    Not meant to replace OpenCode’s SDK; it’s more like a runtime manager around OpenCode for app/backend use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions