Skip to content

Commit 9ac5a52

Browse files
feat: Include LLM headers in ModelConfig
1 parent eb0aba8 commit 9ac5a52

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 8
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-a4a5ea048bb50d06460d81d6828b53b12b19e9224121ee6338dcd1f0781e22a1.yml
3-
openapi_spec_hash: 9b81c0ae04576318d13d7a80d4ab7b5a
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-bc309fd00fe0507f4cbe3bc77fa27d0fbffeaa6e71998778da34de42608a67e8.yml
3+
openapi_spec_hash: 1db1af5c1b068bba1d652102f4454668
44
config_hash: d6c6f623d03971bdba921650e5eb7e5f

src/Sessions/ModelConfig.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* modelName: string,
1616
* apiKey?: string|null,
1717
* baseURL?: string|null,
18+
* headers?: array<string,string>|null,
1819
* provider?: null|Provider|value-of<Provider>,
1920
* }
2021
*/
@@ -41,6 +42,14 @@ final class ModelConfig implements BaseModel
4142
#[Optional]
4243
public ?string $baseURL;
4344

45+
/**
46+
* Custom headers sent with every request to the model provider.
47+
*
48+
* @var array<string,string>|null $headers
49+
*/
50+
#[Optional(map: 'string')]
51+
public ?array $headers;
52+
4453
/**
4554
* AI provider for the model (or provide a baseURL endpoint instead).
4655
*
@@ -73,12 +82,14 @@ public function __construct()
7382
*
7483
* You must use named parameters to construct any parameters with a default value.
7584
*
85+
* @param array<string,string>|null $headers
7686
* @param Provider|value-of<Provider>|null $provider
7787
*/
7888
public static function with(
7989
string $modelName,
8090
?string $apiKey = null,
8191
?string $baseURL = null,
92+
?array $headers = null,
8293
Provider|string|null $provider = null,
8394
): self {
8495
$self = new self;
@@ -87,6 +98,7 @@ public static function with(
8798

8899
null !== $apiKey && $self['apiKey'] = $apiKey;
89100
null !== $baseURL && $self['baseURL'] = $baseURL;
101+
null !== $headers && $self['headers'] = $headers;
90102
null !== $provider && $self['provider'] = $provider;
91103

92104
return $self;
@@ -125,6 +137,19 @@ public function withBaseURL(string $baseURL): self
125137
return $self;
126138
}
127139

140+
/**
141+
* Custom headers sent with every request to the model provider.
142+
*
143+
* @param array<string,string> $headers
144+
*/
145+
public function withHeaders(array $headers): self
146+
{
147+
$self = clone $this;
148+
$self['headers'] = $headers;
149+
150+
return $self;
151+
}
152+
128153
/**
129154
* AI provider for the model (or provide a baseURL endpoint instead).
130155
*

tests/Services/SessionsTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function testActWithOptionalParams(): void
7272
'modelName' => 'openai/gpt-5-nano',
7373
'apiKey' => 'sk-some-openai-api-key',
7474
'baseURL' => 'https://api.openai.com/v1',
75+
'headers' => ['foo' => 'string'],
7576
'provider' => 'openai',
7677
],
7778
'timeout' => 30000,
@@ -138,13 +139,15 @@ public function testExecuteWithOptionalParams(): void
138139
'modelName' => 'openai/gpt-5-nano',
139140
'apiKey' => 'sk-some-openai-api-key',
140141
'baseURL' => 'https://api.openai.com/v1',
142+
'headers' => ['foo' => 'string'],
141143
'provider' => 'openai',
142144
],
143145
'mode' => 'cua',
144146
'model' => [
145147
'modelName' => 'openai/gpt-5-nano',
146148
'apiKey' => 'sk-some-openai-api-key',
147149
'baseURL' => 'https://api.openai.com/v1',
150+
'headers' => ['foo' => 'string'],
148151
'provider' => 'openai',
149152
],
150153
'provider' => 'openai',

0 commit comments

Comments
 (0)