anthropics / anthropics/anthropic-sdk-php

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

Abierto
#67 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
180
Forks
54
Merge medio
12 h 17 min
PR fusionados (30 d)
6

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.