Skip to main content

Overview

CodebuffClient is the primary class for interacting with the Codebuff SDK. It manages configuration, API authentication, and provides methods to run agents and check connection status.

Constructor

new CodebuffClient(options: CodebuffClientOptions)
Creates a new Codebuff client instance with the specified configuration.

Parameters

options
CodebuffClientOptions
required
Configuration options for the client

Throws

Throws an error if API key is not provided and cannot be found in environment variables.

Example

import { CodebuffClient } from '@codebuff/sdk'

const client = new CodebuffClient({
  apiKey: 'your-api-key',
  cwd: process.cwd(),
  maxAgentSteps: 20,
  handleEvent: (event) => {
    if (event.type === 'error') {
      console.error('Error:', event.message)
    }
  }
})

Methods

run()

Run a Codebuff agent with the specified options.
async run(options: RunOptions & CodebuffClientOptions): Promise<RunState>
options
RunOptions & CodebuffClientOptions
required
Run configuration options. Accepts all CodebuffClientOptions plus:
return
Promise<RunState>
Returns a RunState object containing session state and output.

Example

const result = await client.run({
  agent: 'base',
  prompt: 'List all TypeScript files in the src directory',
})

if (result.output.type === 'success') {
  console.log('Success:', result.output.message)
} else {
  console.error('Error:', result.output.message)
}

// Continue the conversation
const followUp = await client.run({
  agent: 'base',
  prompt: 'Now analyze the first file',
  previousRun: result
})

checkConnection()

Check connection to the Codebuff backend by hitting the /healthz endpoint.
async checkConnection(): Promise<boolean>
return
Promise<boolean>
Returns true if connected successfully, false otherwise. Times out after 5 seconds.

Example

const isConnected = await client.checkConnection()
if (!isConnected) {
  console.error('Cannot connect to Codebuff backend')
}

Properties

options

The resolved client configuration including API key and fingerprint ID.
public options: CodebuffClientOptions & {
  apiKey: string
  fingerprintId: string
}

Build docs developers (and LLMs) love