Repository: browserbase/stagehand
File: lib/index.ts (TypeScript)

Code before:
        modelApiKey =
          LLMProvider.getModelProvider(this.modelName) === "openai"
            ? process.env.OPENAI_API_KEY ||
              this.llmClient?.clientOptions?.apiKey
            : LLMProvider.getModelProvider(this.modelName) === "anthropic"
              ? process.env.ANTHROPIC_API_KEY ||
                this.llmClient?.clientOptions?.apiKey
              : LLMProvider.getModelProvider(this.modelName) === "google"
                ? process.env.GOOGLE_API_KEY ||
                  this.llmClient?.clientOptions?.apiKey
                : undefined;
      }
      this.modelClientOptions = {
        ...modelClientOptions,
        apiKey: modelApiKey,
      };
    } else {
      this.modelClientOptions = modelClientOptions;
    }

    if (llmClient) {
      this.llmClient = llmClient;
      this.logger({
        category: "init",
        message:
          "Custom LLM clients are currently not supported in API mode, share your feedback in slack! https://stagehand.dev/slack",
        level: 1,
      });
      this.usingAPI = false;
    } else {
      try {
        // try to set a default LLM client
        this.llmClient = this.llmProvider.getClient(
          this.modelName,
          this.modelClientOptions,
        );
      } catch (error) {
        if (
          error instanceof UnsupportedAISDKModelProviderError ||
          error instanceof InvalidAISDKModelFormatError
        ) {
          throw error;
        }
        this.llmClient = undefined;
      }
    }

    this.domSettleTimeoutMs = domSettleTimeoutMs ?? 30_000;
    this.headless = localBrowserLaunchOptions?.headless ?? false;
    this.browserbaseSessionCreateParams = browserbaseSessionCreateParams;
    this.browserbaseSessionID = browserbaseSessionID;

Review comment (suggestion):
```suggestion
          "Custom LLM clients are currently not supported in API mode",
```

Code after:
        modelApiKey =
          LLMProvider.getModelProvider(this.modelName) === "openai"
            ? process.env.OPENAI_API_KEY ||
              this.llmClient?.clientOptions?.apiKey
            : LLMProvider.getModelProvider(this.modelName) === "anthropic"
              ? process.env.ANTHROPIC_API_KEY ||
                this.llmClient?.clientOptions?.apiKey
              : LLMProvider.getModelProvider(this.modelName) === "google"
                ? process.env.GOOGLE_API_KEY ||
                  this.llmClient?.clientOptions?.apiKey
                : undefined;
      }
      this.modelClientOptions = {
        ...modelClientOptions,
        apiKey: modelApiKey,
      };
    } else {
      this.modelClientOptions = modelClientOptions;
    }

    if (llmClient) {
      this.llmClient = llmClient;
      this.logger({
        category: "init",
        message:
          "Custom LLM clients are currently not supported in API mode",
        level: 1,
      });
      this.usingAPI = false;
    } else {
      try {
        // try to set a default LLM client
        this.llmClient = this.llmProvider.getClient(
          this.modelName,
          this.modelClientOptions,
        );
      } catch (error) {
        if (
          error instanceof UnsupportedAISDKModelProviderError ||
          error instanceof InvalidAISDKModelFormatError
        ) {
          throw error;
        }
        this.llmClient = undefined;
      }
    }

    this.domSettleTimeoutMs = domSettleTimeoutMs ?? 30_000;
    this.headless = localBrowserLaunchOptions?.headless ?? false;
    this.browserbaseSessionCreateParams = browserbaseSessionCreateParams;
    this.browserbaseSessionID = browserbaseSessionID;