Skip to content

Commit 92a4a26

Browse files
jvmvikclaude
andcommitted
Rename API_KEY to SERPAPI_KEY
The test suite, demos and README used API_KEY, while the Ruby client and SerpApi's own documentation use SERPAPI_KEY. Anyone working across both libraries had to keep two names for the same secret. SERPAPI_KEY is now the documented name everywhere. The test helper still falls back to API_KEY so existing local setups keep working, and the workflow reads `secrets.SERPAPI_KEY || secrets.API_KEY` so CI does not break before the repository secret is renamed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 6dddb28 commit 92a4a26

7 files changed

Lines changed: 65 additions & 56 deletions

File tree

‎.github/workflows/serpapi-php.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ jobs:
4949
- name: Run test suite
5050
run: composer run-script test
5151
env:
52-
API_KEY: ${{ secrets.API_KEY }}
52+
SERPAPI_KEY: ${{ secrets.SERPAPI_KEY || secrets.API_KEY }}

‎README.md‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require 'vendor/autoload.php';
4848

4949
use SerpApi\Client;
5050

51-
$client = new Client(getenv('API_KEY'));
51+
$client = new Client(getenv('SERPAPI_KEY'));
5252
$results = $client->search([
5353
'q' => 'coffee',
5454
]);
@@ -86,7 +86,7 @@ The default engine is `google`. You can change it via the second constructor par
8686
```php
8787
use SerpApi\Client;
8888

89-
$client = new Client(getenv('API_KEY'), 'bing');
89+
$client = new Client(getenv('SERPAPI_KEY'), 'bing');
9090
$results = $client->search(['q' => 'coffee']);
9191
```
9292

@@ -97,7 +97,7 @@ The default request timeout is 120 seconds. Customize it via the third construct
9797
```php
9898
use SerpApi\Client;
9999

100-
$client = new Client(getenv('API_KEY'), 'google', 30);
100+
$client = new Client(getenv('SERPAPI_KEY'), 'google', 30);
101101
```
102102

103103
## Search API
@@ -106,7 +106,7 @@ $client = new Client(getenv('API_KEY'), 'google', 30);
106106
```php
107107
use SerpApi\Client;
108108

109-
$client = new Client(getenv('API_KEY'));
109+
$client = new Client(getenv('SERPAPI_KEY'));
110110
$results = $client->search([
111111
'engine' => 'google',
112112
'tbm' => 'isch',
@@ -123,7 +123,7 @@ see: [https://serpapi.com/search-api](https://serpapi.com/search-api)
123123
```php
124124
use SerpApi\Client;
125125

126-
$client = new Client(getenv('API_KEY'));
126+
$client = new Client(getenv('SERPAPI_KEY'));
127127
$results = $client->search([
128128
'engine' => 'google_scholar',
129129
'q' => 'coffee',
@@ -139,7 +139,7 @@ see: [https://serpapi.com/google-scholar-api](https://serpapi.com/google-scholar
139139
```php
140140
use SerpApi\Client;
141141

142-
$client = new Client(getenv('API_KEY'));
142+
$client = new Client(getenv('SERPAPI_KEY'));
143143
$results = $client->search([
144144
'engine' => 'google_autocomplete',
145145
'q' => 'coffee',
@@ -155,7 +155,7 @@ see: [https://serpapi.com/google-autocomplete-api](https://serpapi.com/google-au
155155
```php
156156
use SerpApi\Client;
157157

158-
$client = new Client(getenv('API_KEY'));
158+
$client = new Client(getenv('SERPAPI_KEY'));
159159
$results = $client->search([
160160
'engine' => 'google_shopping',
161161
'q' => 'coffee',
@@ -171,7 +171,7 @@ see: [https://serpapi.com/google-shopping-api](https://serpapi.com/google-shoppi
171171
```php
172172
use SerpApi\Client;
173173

174-
$client = new Client(getenv('API_KEY'));
174+
$client = new Client(getenv('SERPAPI_KEY'));
175175
$results = $client->search([
176176
'engine' => 'google_maps',
177177
'q' => 'pizza',
@@ -189,7 +189,7 @@ see: [https://serpapi.com/google-maps-api](https://serpapi.com/google-maps-api)
189189
```php
190190
use SerpApi\Client;
191191

192-
$client = new Client(getenv('API_KEY'));
192+
$client = new Client(getenv('SERPAPI_KEY'));
193193
$results = $client->search([
194194
'engine' => 'google_jobs',
195195
'q' => 'coffee',
@@ -205,7 +205,7 @@ see: [https://serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)
205205
```php
206206
use SerpApi\Client;
207207

208-
$client = new Client(getenv('API_KEY'));
208+
$client = new Client(getenv('SERPAPI_KEY'));
209209
$results = $client->search([
210210
'engine' => 'google_events',
211211
'q' => 'Events in Austin',
@@ -222,7 +222,7 @@ see: [https://serpapi.com/google-events-api](https://serpapi.com/google-events-a
222222
```php
223223
use SerpApi\Client;
224224

225-
$client = new Client(getenv('API_KEY'));
225+
$client = new Client(getenv('SERPAPI_KEY'));
226226
$results = $client->search([
227227
'engine' => 'google_lens',
228228
'url' => 'https://i.imgur.com/5bGzZi7.jpg',
@@ -240,7 +240,7 @@ see: [https://serpapi.com/google-lens-api](https://serpapi.com/google-lens-api)
240240
```php
241241
use SerpApi\Client;
242242

243-
$client = new Client(getenv('API_KEY'));
243+
$client = new Client(getenv('SERPAPI_KEY'));
244244
$results = $client->search([
245245
'engine' => 'google_play',
246246
'q' => 'kite',
@@ -257,7 +257,7 @@ see: [https://serpapi.com/google-play-api](https://serpapi.com/google-play-api)
257257
```php
258258
use SerpApi\Client;
259259

260-
$client = new Client(getenv('API_KEY'));
260+
$client = new Client(getenv('SERPAPI_KEY'));
261261
$results = $client->search([
262262
'engine' => 'google_local_services',
263263
'q' => 'electrician',
@@ -274,7 +274,7 @@ see: [https://serpapi.com/google-local-services-api](https://serpapi.com/google-
274274
```php
275275
use SerpApi\Client;
276276

277-
$client = new Client(getenv('API_KEY'));
277+
$client = new Client(getenv('SERPAPI_KEY'));
278278
$results = $client->search([
279279
'engine' => 'bing',
280280
'q' => 'coffee',
@@ -290,7 +290,7 @@ see: [https://serpapi.com/bing-search-api](https://serpapi.com/bing-search-api)
290290
```php
291291
use SerpApi\Client;
292292

293-
$client = new Client(getenv('API_KEY'));
293+
$client = new Client(getenv('SERPAPI_KEY'));
294294
$results = $client->search([
295295
'engine' => 'baidu',
296296
'q' => 'coffee',
@@ -306,7 +306,7 @@ see: [https://serpapi.com/baidu-search-api](https://serpapi.com/baidu-search-api
306306
```php
307307
use SerpApi\Client;
308308

309-
$client = new Client(getenv('API_KEY'));
309+
$client = new Client(getenv('SERPAPI_KEY'));
310310
$results = $client->search([
311311
'engine' => 'yahoo',
312312
'p' => 'coffee',
@@ -322,7 +322,7 @@ see: [https://serpapi.com/yahoo-search-api](https://serpapi.com/yahoo-search-api
322322
```php
323323
use SerpApi\Client;
324324

325-
$client = new Client(getenv('API_KEY'));
325+
$client = new Client(getenv('SERPAPI_KEY'));
326326
$results = $client->search([
327327
'engine' => 'youtube',
328328
'search_query' => 'coffee',
@@ -338,7 +338,7 @@ see: [https://serpapi.com/youtube-search-api](https://serpapi.com/youtube-search
338338
```php
339339
use SerpApi\Client;
340340

341-
$client = new Client(getenv('API_KEY'));
341+
$client = new Client(getenv('SERPAPI_KEY'));
342342
$results = $client->search([
343343
'engine' => 'walmart',
344344
'query' => 'coffee',
@@ -354,7 +354,7 @@ see: [https://serpapi.com/walmart-search-api](https://serpapi.com/walmart-search
354354
```php
355355
use SerpApi\Client;
356356

357-
$client = new Client(getenv('API_KEY'));
357+
$client = new Client(getenv('SERPAPI_KEY'));
358358
$results = $client->search([
359359
'engine' => 'ebay',
360360
'_nkw' => 'water',
@@ -370,7 +370,7 @@ see: [https://serpapi.com/ebay-search-api](https://serpapi.com/ebay-search-api)
370370
```php
371371
use SerpApi\Client;
372372

373-
$client = new Client(getenv('API_KEY'));
373+
$client = new Client(getenv('SERPAPI_KEY'));
374374
$results = $client->search([
375375
'engine' => 'naver',
376376
'query' => 'coffee',
@@ -386,7 +386,7 @@ see: [https://serpapi.com/naver-search-api](https://serpapi.com/naver-search-api
386386
```php
387387
use SerpApi\Client;
388388

389-
$client = new Client(getenv('API_KEY'));
389+
$client = new Client(getenv('SERPAPI_KEY'));
390390
$results = $client->search([
391391
'engine' => 'home_depot',
392392
'q' => 'table',
@@ -402,7 +402,7 @@ see: [https://serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-
402402
```php
403403
use SerpApi\Client;
404404

405-
$client = new Client(getenv('API_KEY'));
405+
$client = new Client(getenv('SERPAPI_KEY'));
406406
$results = $client->search([
407407
'engine' => 'apple_app_store',
408408
'term' => 'coffee',
@@ -418,7 +418,7 @@ see: [https://serpapi.com/apple-app-store](https://serpapi.com/apple-app-store)
418418
```php
419419
use SerpApi\Client;
420420

421-
$client = new Client(getenv('API_KEY'));
421+
$client = new Client(getenv('SERPAPI_KEY'));
422422
$results = $client->search([
423423
'engine' => 'duckduckgo',
424424
'q' => 'coffee',
@@ -437,7 +437,7 @@ see: [https://serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-
437437
```php
438438
use SerpApi\Client;
439439

440-
$client = new Client(getenv('API_KEY'));
440+
$client = new Client(getenv('SERPAPI_KEY'));
441441
$locations = $client->location(['q' => 'Austin', 'limit' => 3]);
442442

443443
echo "Number of locations: " . count($locations) . "\n";
@@ -453,7 +453,7 @@ First, run a search and save the search ID:
453453
```php
454454
use SerpApi\Client;
455455

456-
$client = new Client(getenv('API_KEY'));
456+
$client = new Client(getenv('SERPAPI_KEY'));
457457
$results = $client->search([
458458
'q' => 'Coffee',
459459
'location' => 'Austin, Texas',
@@ -473,7 +473,7 @@ print_r($archived);
473473
```php
474474
use SerpApi\Client;
475475

476-
$client = new Client(getenv('API_KEY'));
476+
$client = new Client(getenv('SERPAPI_KEY'));
477477
$account = $client->account();
478478
print_r($account);
479479
```
@@ -483,7 +483,7 @@ print_r($account);
483483
```php
484484
use SerpApi\Client;
485485

486-
$client = new Client(getenv('API_KEY'));
486+
$client = new Client(getenv('SERPAPI_KEY'));
487487
$html = $client->html(['q' => 'Coffee']);
488488

489489
echo strlen($html) . " bytes of HTML\n";
@@ -522,7 +522,7 @@ The `tests/` directory includes specifications which serve the dual purposes of
522522
Set your secret API key in your shell before running tests:
523523

524524
```bash
525-
export API_KEY="your_secret_key"
525+
export SERPAPI_KEY="your_secret_key"
526526
```
527527

528528
Install dependencies and run the test suite:

‎README.md.erb‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def snippet(path)
1515
property = source[/assertResponseHasProperty\(\$response,\s*'([^']+)'/, 1] || 'organic_results'
1616

1717
code = "use SerpApi\\Client;\n\n"
18-
code += "$client = new Client(getenv('API_KEY'));\n"
18+
code += "$client = new Client(getenv('SERPAPI_KEY'));\n"
1919
code += "$results = $client->search(#{params});\n\n"
2020
code += "print_r($results->#{property});\n"
2121

@@ -72,7 +72,7 @@ require 'vendor/autoload.php';
7272

7373
use SerpApi\Client;
7474

75-
$client = new Client(getenv('API_KEY'));
75+
$client = new Client(getenv('SERPAPI_KEY'));
7676
$results = $client->search([
7777
'q' => 'coffee',
7878
]);
@@ -110,7 +110,7 @@ The default engine is `google`. You can change it via the second constructor par
110110
```php
111111
use SerpApi\Client;
112112

113-
$client = new Client(getenv('API_KEY'), 'bing');
113+
$client = new Client(getenv('SERPAPI_KEY'), 'bing');
114114
$results = $client->search(['q' => 'coffee']);
115115
```
116116

@@ -121,7 +121,7 @@ The default request timeout is 120 seconds. Customize it via the third construct
121121
```php
122122
use SerpApi\Client;
123123

124-
$client = new Client(getenv('API_KEY'), 'google', 30);
124+
$client = new Client(getenv('SERPAPI_KEY'), 'google', 30);
125125
```
126126

127127
## Search API
@@ -213,7 +213,7 @@ see: [https://serpapi.com/duckduckgo-search-api](https://serpapi.com/duckduckgo-
213213
```php
214214
use SerpApi\Client;
215215

216-
$client = new Client(getenv('API_KEY'));
216+
$client = new Client(getenv('SERPAPI_KEY'));
217217
$locations = $client->location(['q' => 'Austin', 'limit' => 3]);
218218

219219
echo "Number of locations: " . count($locations) . "\n";
@@ -229,7 +229,7 @@ First, run a search and save the search ID:
229229
```php
230230
use SerpApi\Client;
231231

232-
$client = new Client(getenv('API_KEY'));
232+
$client = new Client(getenv('SERPAPI_KEY'));
233233
$results = $client->search([
234234
'q' => 'Coffee',
235235
'location' => 'Austin, Texas',
@@ -249,7 +249,7 @@ print_r($archived);
249249
```php
250250
use SerpApi\Client;
251251

252-
$client = new Client(getenv('API_KEY'));
252+
$client = new Client(getenv('SERPAPI_KEY'));
253253
$account = $client->account();
254254
print_r($account);
255255
```
@@ -259,7 +259,7 @@ print_r($account);
259259
```php
260260
use SerpApi\Client;
261261

262-
$client = new Client(getenv('API_KEY'));
262+
$client = new Client(getenv('SERPAPI_KEY'));
263263
$html = $client->html(['q' => 'Coffee']);
264264

265265
echo strlen($html) . " bytes of HTML\n";
@@ -298,7 +298,7 @@ The `tests/` directory includes specifications which serve the dual purposes of
298298
Set your secret API key in your shell before running tests:
299299

300300
```bash
301-
export API_KEY="your_secret_key"
301+
export SERPAPI_KEY="your_secret_key"
302302
```
303303

304304
Install dependencies and run the test suite:

‎demo/demo.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Prerequisites:
77
* - composer install
8-
* - export API_KEY="your secret key" (get one at https://serpapi.com/dashboard)
8+
* - export SERPAPI_KEY="your secret key" (get one at https://serpapi.com/dashboard)
99
*
1010
* Usage:
1111
* php demo/demo.php
@@ -15,9 +15,9 @@
1515

1616
use SerpApi\Client;
1717

18-
$api_key = getenv('API_KEY');
18+
$api_key = getenv('SERPAPI_KEY');
1919
if (empty($api_key)) {
20-
fwrite(STDERR, "API_KEY environment variable must be set\n");
20+
fwrite(STDERR, "SERPAPI_KEY environment variable must be set\n");
2121
exit(1);
2222
}
2323

‎demo/demo_async.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* is much faster than running the searches one after another.
1010
*
1111
* Usage:
12-
* export API_KEY="your secret key"
12+
* export SERPAPI_KEY="your secret key"
1313
* php demo/demo_async.php
1414
*/
1515

@@ -31,9 +31,9 @@ function search_metadata($response): object {
3131
return $response->search_metadata;
3232
}
3333

34-
$api_key = getenv('API_KEY');
34+
$api_key = getenv('SERPAPI_KEY');
3535
if (empty($api_key)) {
36-
fwrite(STDERR, "API_KEY environment variable must be set\n");
36+
fwrite(STDERR, "SERPAPI_KEY environment variable must be set\n");
3737
exit(1);
3838
}
3939

0 commit comments

Comments
 (0)