Login and extract data
Custom logger
Integrate with your logging framework:Download and export files
Using different AI providers
Pass the provider and model in theai config:
AiConfig type reference.Practical SDK examples for common automation scenarios.
import { Refrain, loadRunbook } from "@refrainai/sdk";
const client = new Refrain({
ai: {
modelId: "claude-sonnet-4-6",
provider: "anthropic",
apiKey: process.env.ANTHROPIC_API_KEY!,
},
headless: true,
});
const runbook = await loadRunbook("./runbooks/login-and-extract.yaml");
const report = await client.execute(runbook, {
contextMarkdown: "# Credentials\n- Use staging environment",
variables: { email: "[email protected]" },
secrets: { password: process.env.APP_PASSWORD! },
screenshotDir: "./screenshots",
});
// Access captured values
for (const step of report.steps) {
if (step.capturedValues) {
console.log(`Step ${step.ordinal}:`, step.capturedValues);
}
}
console.log(`Result: ${report.succeeded}/${report.totalSteps} succeeded`);
await client.dispose();
import { Refrain, CallbackLogger, loadRunbook } from "@refrainai/sdk";
import type { LoggerFactory } from "@refrainai/sdk";
const loggerFactory: LoggerFactory = {
createLogger: () =>
new CallbackLogger((level, message) => {
// Forward to your logger (e.g., winston, pino)
console.log(`[refrain:${level}] ${message}`);
}),
createSpinner: () => ({
start: (msg) => console.log(`[spinner] ${msg}...`),
stop: (msg) => console.log(`[spinner] ${msg}`),
}),
};
const client = new Refrain({
ai: {
modelId: "claude-sonnet-4-6",
provider: "anthropic",
apiKey: process.env.ANTHROPIC_API_KEY!,
},
loggerFactory,
debug: true,
});
const runbook = await loadRunbook("./flow.yaml");
const report = await client.execute(runbook, {
contextMarkdown: "",
debugLogPath: "./debug.jsonl",
});
await client.dispose();
import { Refrain, loadRunbook } from "@refrainai/sdk";
const client = new Refrain({
ai: {
modelId: "claude-sonnet-4-6",
provider: "anthropic",
apiKey: process.env.ANTHROPIC_API_KEY!,
},
});
const runbook = await loadRunbook("./runbooks/export-data.yaml");
const report = await client.execute(runbook, {
contextMarkdown: "",
outputDir: "./output",
mergeDownloads: true,
});
if (report.downloadedFiles?.length) {
console.log("Downloaded:", report.downloadedFiles);
}
await client.dispose();
ai config:
const client = new Refrain({
ai: {
modelId: "gpt-4o",
provider: "openai",
apiKey: process.env.OPENAI_API_KEY!,
},
});
AiConfig type reference.