Skip to content
Merged
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
41 changes: 32 additions & 9 deletions docs/configuration/models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,46 +156,69 @@ stagehand = Stagehand(
## Custom LLM Integration

<Note>
Custom LLMs are currently only supported in TypeScript.
Only [LiteLLM compatible providers](https://docs.litellm.ai/docs/providers) are available in Python. Some may require extra setup.
</Note>

Integrate any LLM with Stagehand using custom clients. The only requirement is **structured output support** for consistent automation behavior.

### Vercel AI SDK
The [Vercel AI SDK](https://sdk.vercel.ai/providers/ai-sdk-providers) is a popular library for interacting with LLMs. You can use any of the providers supported by the Vercel AI SDK to create a client for your model, **as long as they support structured outputs**.

Vercel AI SDK supports providers for OpenAI, Anthropic, and Google, along with support for **Amazon Bedrock** and **Azure OpenAI**.
Vercel AI SDK supports providers for OpenAI, Anthropic, and Google, along with support for **Amazon Bedrock** and **Azure OpenAI**. For a full list, see the [Vercel AI SDK providers page](https://sdk.vercel.ai/providers/ai-sdk-providers).

To get started, you'll need to install the `ai` package and the provider you want to use. For example, to use Amazon Bedrock, you'll need to install the `@ai-sdk/amazon-bedrock` package.
To get started, you'll need to install the `ai` package (version 4) and the provider you want to use (version 1 - both need to be compatible with LanguageModelV1). For example, to use Amazon Bedrock, you'll need to install the `@ai-sdk/amazon-bedrock` package.

You'll also need to import the [Vercel AI SDK external client](https://github.com/browserbase/stagehand/blob/main/lib/llm/aisdk.ts) which is exposed as `AISdkClient` to create a client for your model.
You'll also need to import the [Vercel AI SDK external client](https://github.com/browserbase/stagehand/blob/main/lib/llm/aisdk.ts) through Stagehand to create a client for your model.

<Tabs>
<Tab title="npm">
```bash
npm install ai @ai-sdk/amazon-bedrock
npm install ai@4 @ai-sdk/amazon-bedrock@1
```
</Tab>

<Tab title="pnpm">
```bash
pnpm install ai @ai-sdk/amazon-bedrock
pnpm install ai@4 @ai-sdk/amazon-bedrock@1
```
</Tab>

<Tab title="yarn">
```bash
yarn add ai @ai-sdk/amazon-bedrock
yarn add ai@4 @ai-sdk/amazon-bedrock@1
```
</Tab>
</Tabs>

To get started, you can use the [Vercel AI SDK external client](https://github.com/browserbase/stagehand/blob/main/lib/llm/aisdk.ts) which is exposed as `AISdkClient` to create a client for your model.
<Note>
The `AISdkClient` is not yet available via the Stagehand npm package. For now, install Stagehand as a git repository to access the `AISdkClient` (this will be included in the npm package in an upcoming release).
</Note>

<Tabs>
<Tab title="npm">
```bash
npm install @browserbasehq/stagehand@git+https://github.com/browserbase/stagehand.git
```
</Tab>

<Tab title="pnpm">
```bash
pnpm install @browserbasehq/stagehand@git+https://github.com/browserbase/stagehand.git
```
</Tab>

<Tab title="yarn">
```bash
yarn add @browserbasehq/stagehand@git+https://github.com/browserbase/stagehand.git
```
</Tab>
</Tabs>

```ts
// Install/import the provider you want to use.
// For example, to use OpenAI, import `openai` from @ai-sdk/openai
// For example, to use Azure OpenAI, import { createAzure } from '@ai-sdk/azure';
import { bedrock } from "@ai-sdk/amazon-bedrock";
// @ts-ignore
import { AISdkClient } from "@browserbasehq/stagehand";
Comment on lines +221 to 222
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Using @ts-ignore should be avoided when possible. Consider using a more specific TypeScript suppression or adding proper type declarations.

Suggested change
// @ts-ignore
import { AISdkClient } from "@browserbasehq/stagehand";
// TODO: Remove this when AISdkClient is properly exported with types
import { AISdkClient } from "@browserbasehq/stagehand";


const stagehand = new Stagehand({
Expand Down