anthropics / anthropics/anthropic-sdk-php

List-type query params are serialised as types[0]= instead of types[]=, causing a 400

Aperta
#67 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
180
Fork
54
Merge medio
12h 17m
PR unite (30g)
6

Descrizione

Hi, I'm running into an issue with list-valued query params - they're serialised with indexed keys, which the API rejects. As far as I can tell this makes any endpoint taking a list query param unusable via the sdk.

**Repro** (v0.41.0):

```php
$client = new Anthropic\Client(apiKey: getenv('ANTHROPIC_API_KEY'));

$client->beta->sessions->events->list(
'sesn_XXXX',
types: ['session.usage'],
betas: ['managed-agents-2026-04-01'],
);
```

**Result:**

```
PHP Fatal error: Uncaught Anthropic\Core\Exceptions\BadRequestException: Anthropic Bad Request Exception
{
"status": 400,
"body": {
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Unknown query parameter 'types[0]'. Valid parameters: created_at[gt], created_at[gte], created_at[lt], created_at[lte], limit, order, page, types[]."
},
"request_id": "req_011Cduwz9HqW8WLyFkJnT1EL"
}
} in vendor/anthropic-ai/sdk/src/Core/Exceptions/APIStatusException.php:67
Stack trace:
#0 src/Core/BaseClient.php(367): Anthropic\Core\Exceptions\APIStatusException::from(Object(Nyholm\Psr7\Request), Object(Nyholm\Psr7\Response))
#1 src/Core/BaseClient.php(93): Anthropic\Core\BaseClient->sendRequest(Object(Anthropic\RequestOptions), Object(Nyholm\Psr7\Request), NULL, 0, 0)
#2 src/Services/Beta/Sessions/EventsRawService.php(123): Anthropic\Core\BaseClient->request('GET', Array, Array, Array, NULL, NULL, ...)
#3 src/Services/Beta/Sessions/EventsService.php(123): Anthropic\Services\Beta\Sessions\EventsRawService->list('sesn_...', Array, NULL)
#4 repro.php(7): Anthropic\Services\Beta\Sessions\EventsService->list('sesn_...', NULL, NULL, NULL, NULL, NULL, NULL, NULL, Array, Array)
```

The SDK sends `types%5B0%5D=session.usage`; the API accepts `types%5B%5D=session.usage`.

**Cause:** `src/Core/Util.php:255` and `src/Core/RequestTransformer.php:146` use `http_build_query()`, which always emits indexed keys for lists and has no repeated-key mode. Affects all list-valued query params. Named sub-keys like `created_at[gt]` are fine.

**Fix:** serialise lists as repeated `key[]=` pairs.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.