Can Stagehand Python SDK work with non-OpenAI models like DeepSeek or Qwen? #1832
Replies: 2 comments
|
For the current Python SDK, don't use the TS-style custom OpenAI client path. The v3 migration docs say custom Python LLM client classes aren't supported yet, but OpenAI-compatible custom endpoints / proxies are supported. The supported shape is to pass the model key on the client and the model name when starting the session: client = Stagehand(
browserbase_api_key=os.environ["BROWSERBASE_API_KEY"],
model_api_key=os.environ["DEEPSEEK_API_KEY"],
)
session = client.sessions.start(
model_name="deepseek/deepseek-chat",
x_language="python",
)So DeepSeek should be used as a first-class |
|
This thread predates Stagehand v4. The current Python SDK supports arbitrary providers through the BYO LLM callback, so DeepSeek/Qwen do not need to be modeled as built-in providers. For an OpenAI-compatible endpoint, create an AsyncOpenAI client with the provider's base_url, implement an async generate(params) callback, and pass it to Stagehand.create(..., model=generate). The callback should map params.messages and return LLMStructuredGenerateResult, including parsed structured_content when Stagehand requests a JSON schema. The current v4 docs include complete Python examples: If you use a built-in Model Gateway model, use provider/model plus model_api_key. For a raw DeepSeek, Qwen, or DashScope endpoint, the callback path is the supported route; Model Gateway itself requires a Browserbase-hosted browser. |
Uh oh!
There was an error while loading. Please reload this page.
I’ve successfully used Stagehand with TypeScript to run browser automation powered by third-party LLMs such as DeepSeek and Qwen (Tongyi Qianwen) by configuring custom baseURL and API keys via the OpenAI-compatible interface.
However, I’m struggling to achieve the same in Python. The official documentation doesn’t clearly state whether the Python SDK supports plugging in non-Gemini/GPT/Claude models — especially those that are OpenAI-compatible (like DeepSeek or Qwen).
Has anyone successfully integrated DeepSeek, Qwen, or other OpenAI-compatible LLMs into Stagehand’s Python SDK?
If so, could you please share:
The correct way to configure the client or environment variables?
Whether the Python SDK truly supports arbitrary OpenAI-compatible endpoints?
Any working code examples would be greatly appreciated!
I believe this would help many developers in regions where GPT/Claude aren’t easily accessible but local models (e.g., from Alibaba, DeepSeek) are preferred for cost, latency, or compliance reasons.
Thanks in advance! 🙏
All reactions