Skip to content

SDK Integration

Quick Reference

  • Who: Developer
  • Where: Any Node.js/Bun application
  • Time: ~15 minutes to integrate
  • Prerequisites: Node.js ≥18, npm, API key
  • Node.js ≥18 or Bun installed
  • Codebuff API key (from codebuff.com/profile)
  • A project to integrate with
Terminal window
npm install @codebuff/sdk
import { CodebuffClient } from '@codebuff/sdk'
const client = new CodebuffClient({
apiKey: 'your-api-key',
cwd: '/path/to/your/project',
onError: (error) => console.error('Codebuff error:', error.message),
})

(sdk/src/client.ts)

const result = await client.run({
agent: 'base',
prompt: 'Add error handling to all API endpoints',
handleEvent: (event) => {
console.log('Progress:', event)
},
})
import type { AgentDefinition } from '@codebuff/sdk'
const myAgent: AgentDefinition = {
id: 'code-reviewer',
displayName: 'Code Reviewer',
model: 'openai/gpt-5.1',
instructionsPrompt: 'Review code for best practices and potential issues.',
}
const result = await client.run({
agent: 'code-reviewer',
agentDefinitions: [myAgent],
prompt: 'Review the authentication module',
customToolDefinitions: [],
handleEvent: (event) => {
console.log('Review progress:', event)
},
})

(sdk/src/run.ts)

const customTool = {
name: 'check_deployment',
description: 'Check the deployment status of the application',
parameters: {
type: 'object',
properties: {
environment: { type: 'string', enum: ['staging', 'production'] }
}
},
handler: async (params) => {
// Your custom logic
return { status: 'deployed', version: '1.2.3' }
}
}
const result = await client.run({
agent: 'base',
prompt: 'Check if staging is deployed',
customToolDefinitions: [customTool],
})

(sdk/src/custom-tool.ts)

  • ✅ SDK connects to Codebuff API
  • ✅ Agents execute and return structured results
  • ✅ Progress events stream in real-time
  • ✅ File changes applied to the specified directory
🔴 Error: Invalid API key

Cause: The API key is incorrect or expired.

Solution:

  1. Verify your API key at codebuff.com/profile
  2. Ensure you’re using the correct key format
  3. Check that your account is active
Q: What's the difference between the CLI and SDK?

A: The CLI provides an interactive terminal UI for direct developer use. The SDK is a programmatic API for embedding agent workflows in applications, CI/CD pipelines, or custom tools. Both use the same underlying agent runtime.