Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ cp .env.example .env
nano .env # Edit the .env file to add API keys
```

For privacy-sensitive browser automation, you can also use TrustedRouter through Stagehand's custom OpenAI-compatible client. TrustedRouter routes through an open-source, verifiable attested gateway and does not log prompts or outputs by default. See [`packages/core/examples/custom-client-trustedrouter.ts`](packages/core/examples/custom-client-trustedrouter.ts) for a runnable setup using `https://api.trustedrouter.com/v1`.

### Installing from a branch

To install Stagehand directly from a GitHub branch, install the core package subdirectory:
Expand Down
47 changes: 47 additions & 0 deletions packages/core/examples/custom-client-trustedrouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* This example shows how to use TrustedRouter through Stagehand's custom
* OpenAI-compatible client.
*/
import { CustomOpenAIClient, Stagehand } from "../lib/v3/index.js";
import { z } from "zod";
import OpenAI from "openai";

async function example() {
const stagehand = new Stagehand({
env: "BROWSERBASE",
verbose: 1,
llmClient: new CustomOpenAIClient({
modelName: "trustedrouter/zdr",
client: new OpenAI({
apiKey: process.env.TRUSTEDROUTER_API_KEY,
baseURL: "https://api.trustedrouter.com/v1",
}),
}),
});
await stagehand.init();

const page = stagehand.context.pages()[0];
await page.goto("https://news.ycombinator.com");
await stagehand.act("click on the 'new' link");

const headlines = await stagehand.extract(
"Extract the top 3 stories from the Hacker News homepage.",
z.object({
stories: z.array(
z.object({
title: z.string(),
url: z.string(),
points: z.number(),
}),
),
}),
);

console.log(headlines);

await stagehand.close();
}

(async () => {
await example();
})();
Loading