RuntimeeRuntimee
Guides

Best Practices

Best practices for using Runtimee

Best Practices

Follow these best practices when using Runtimee in your autonomous systems.

1. Use Environment Variables for Secrets

Never hardcode your API key or other secrets in your source code.

// Bad
const rt = new Runtimee({ apiKey: "sk_live_1234567890abcdef" })

// Good
const rt = new Runtimee({
  apiKey: process.env.RUNTIMEE_API_KEY
})

2. Handle All Authorization Decisions

Always handle all three possible authorization decisions: approved, denied, and pending-review.

const { decision, policyResults } = await rt.actors.previewPay(actor.id, { /* ... */ })

switch (decision) {
  case "approved":
    // Proceed with payment
    break
  case "denied":
    // Handle denial (e.g., notify user, log, etc.)
    break
  case "pending-review":
    // Handle pending review (e.g., flag for manual review)
    break
}

3. Use Idempotency Keys for Payments

To avoid duplicate payments, use idempotency keys when making payments.

const execution = await rt.actors.pay(actor.id, {
  target: "openai:gpt-4-turbo",
  amount: "5",
  purpose: { type: "llm-inference", id: "chat-001" },
  idempotencyKey: "unique-key-for-this-request" // e.g., UUID or request ID
})

4. Set Reasonable Budget Limits

Start with conservative budget limits and increase as needed.

// Start with a small budget for testing
const actor = await rt.actors.create({
  name: "test-agent",
  budget: { amount: "10", currency: "USDC", period: "monthly" }, // 10 USDC
  policies: [ /* ... */ ]
})

5. Monitor Actor Status Regularly

Regularly check actor status to detect issues early.

// Check status every hour or before critical operations
const status = await rt.actors.status(actor.id)
if (status.status === "frozen") {
  // Handle frozen actor
}
if (parseFloat(status.budget.remaining) < 10) {
  // Warn about low budget
}

How is this guide?

On this page