Skip to main content

TypeScript / Node.js

Install the official TypeScript SDK:
npm install @stewrd/sdk

Quick Start

import { Stewrd } from '@stewrd/sdk'

const stewrd = new Stewrd('sk-stw_your_key')

const result = await stewrd.agent.run({
  message: 'Research the top 5 CRM tools and create a comparison spreadsheet',
  capabilities: ['research', 'documents'],
})

console.log(result.message)
console.log(result.files[0].url)

Streaming

const stream = await stewrd.agent.stream({
  message: 'Write a detailed analysis',
})

for await (const event of stream) {
  if (event.type === 'token') process.stdout.write(event.content)
  if (event.type === 'tool_start') console.log(`Using ${event.tool}...`)
  if (event.type === 'done') console.log('\n\nTokens:', event.usage.tokens_used)
}

Custom Tools (Function Calling)

Use runWithTools to let the agent call your functions — the SDK handles the loop automatically:
const result = await stewrd.agent.runWithTools(
  {
    message: 'Check order #12345 and email the customer a summary',
    tools: [
      {
        name: 'get_order',
        description: 'Look up an order by ID',
        parameters: {
          type: 'object',
          properties: { order_id: { type: 'string' } },
          required: ['order_id'],
        },
      },
      {
        name: 'send_email',
        description: 'Send an email to a customer',
        parameters: {
          type: 'object',
          properties: {
            to: { type: 'string' },
            subject: { type: 'string' },
            body: { type: 'string' },
          },
          required: ['to', 'subject', 'body'],
        },
      },
    ],
  },
  async (toolCall) => {
    // Execute the tool in your system and return the result as a string
    if (toolCall.name === 'get_order') {
      const order = await db.orders.findById(toolCall.arguments.order_id as string)
      return JSON.stringify(order)
    }
    if (toolCall.name === 'send_email') {
      await emailService.send(toolCall.arguments)
      return JSON.stringify({ sent: true })
    }
    return JSON.stringify({ error: 'Unknown tool' })
  }
)

console.log(result.message)
For more control, use submitToolOutputs directly to handle the loop yourself. See the Custom Tools guide for details.

Error Handling

import { Stewrd, StewrdError } from '@stewrd/sdk'

try {
  await stewrd.agent.run({ message: '...' })
} catch (err) {
  if (err instanceof StewrdError) {
    console.log(err.status)  // 401
    console.log(err.code)    // 'invalid_api_key'
    console.log(err.message) // 'Invalid API key'
  }
}

View on GitHub

Source code, issues, and full API reference.

View on npm

@stewrd/sdk on npm

Python

Install the official Python SDK:
pip install stewrd

Quick Start

from stewrd import Stewrd

stewrd = Stewrd("sk-stw_your_key")

result = stewrd.agent.run(
    message="Research the top 5 CRM tools and create a comparison spreadsheet",
    capabilities=["research", "documents"],
)

print(result.message)
print(result.files[0].url)

Streaming

for event in stewrd.agent.stream(message="Write a detailed analysis"):
    if event.type == "token":
        print(event.content, end="")
    if event.type == "tool_start":
        print(f"Using {event.tool}...")
    if event.type == "done":
        print(f"\n\nTokens: {event.usage.tokens_used}")

Error Handling

from stewrd import Stewrd, StewrdError

try:
    stewrd.agent.run(message="...")
except StewrdError as e:
    print(e.status)   # 401
    print(e.code)     # "invalid_api_key"
    print(e.message)  # "Invalid API key"

View on GitHub

Source code, issues, and full API reference.

View on PyPI

stewrd on PyPI

Available SDKs

LanguagePackageStatus
TypeScript / Node.js@stewrd/sdkAvailable
PythonstewrdAvailable

Using Fetch Directly

The Stewrd API is a single REST endpoint, so it’s straightforward to use with fetch in any language:
const response = await fetch('https://api.stewrd.dev/v1/agent', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.STEWRD_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Your task here',
  }),
})

const data = await response.json()