# Raw Requests

**Package:** Anthropic PHP | **Version:** 1 | **URL:** https://mozex.dev/docs/anthropic-php/v1/usage/raw-requests

---

`request()` sends a request to any API path, for an endpoint the client has no method for yet. It goes through the same transport as every other call: your key, the configured headers, retries, middleware and per-request options all apply, and an error status throws the same typed exception (see [Error Handling](https://mozex.dev/docs/anthropic-php/v1/reference/error-handling)).

```php
$response = $client->request('GET', 'skills', ['limit' => 20]);

$response->status;            // 200
$response->data;              // ['data' => [...], 'next_page' => 'next_page']
$response->meta()->requestId; // 'req_018EeWyXxfu5pfWkrYcMdjWG'
```

## Paths and parameters

The path is relative to the API root, and the form the API reference prints works too: `/v1/skills` and `skills` go to the same place.

For `GET` and `DELETE`, the parameters go in the query string, with a list sent as `key[]=value` once per value. For `POST` and `PUT`, they go in a JSON body:

```php
$response = $client->request('POST', 'messages/count_tokens', [
    'model' => 'claude-opus-5-5',
    'messages' => [
        ['role' => 'user', 'content' => 'Hello, world'],
    ],
]);

$response->data['input_tokens']; // 10
```

A `betas` parameter becomes the `anthropic-beta` header, as on every other method. The method can be written in any case; `PATCH` and other methods the API doesn't use throw an `InvalidArgumentException` before anything is sent. Raw requests send JSON only, so uploads still go through `files()->upload()`, and they don't stream: a `'stream' => true` request waits for the whole answer and returns the event text, so use `messages()->createStreamed()` for that. A full URL in place of the path throws. A raw request doesn't follow `next_page` either; pass it back as `page` for the next page.

## The response

`data` is the decoded body when the API answers with a JSON object or array (`application/json`), and the body's text otherwise, such as an empty string for a `204` or the lines of a JSONL answer. `status` is the HTTP status. `meta()` reads the request ID and the rate-limit headers like every other response (see [Meta Information](https://mozex.dev/docs/anthropic-php/v1/reference/meta-information)).

## Testing

`ClientFake` answers raw requests from its queue. Queue a `RawResponse::fake()` with the body you want back, and assert on `Raw::class`:

```php
use Anthropic\Resources\Raw;
use Anthropic\Responses\Raw\RawResponse;
use Anthropic\Testing\ClientFake;

$client = new ClientFake([
    RawResponse::fake(['data' => [], 'next_page' => null]),
]);

$client->request('GET', 'skills', ['limit' => 20]);

$client->assertSent(Raw::class, function (string $method, string $httpMethod, string $path, array $parameters): bool {
    return $httpMethod === 'GET' && $path === 'skills' && $parameters['limit'] === 20;
});
```

The fake records the path as you passed it, and throws on a method the client would reject. `RawResponse::fake()` takes the whole body rather than overrides, the meta information second as on every other fake, and the status third: `RawResponse::fake('', status: 204)` fakes an answer without a body.

For the endpoints themselves, see the [Anthropic API reference](https://platform.claude.com/docs/en/api/overview).

---

## Table of Contents

- [Introduction](https://mozex.dev/docs/anthropic-php/v1)
- [AI Integration](https://mozex.dev/docs/anthropic-php/v1/ai-integration)
- [Support Us](https://mozex.dev/docs/anthropic-php/v1/support-us)
- [Requirements](https://mozex.dev/docs/anthropic-php/v1/requirements)
- [Changelog](https://mozex.dev/docs/anthropic-php/v1/changelog)
- [Contributing](https://mozex.dev/docs/anthropic-php/v1/contributing)
- [Questions & Issues](https://mozex.dev/docs/anthropic-php/v1/questions-and-issues)
- [About Mozex](https://mozex.dev/docs/anthropic-php/v1/about)

### Usage

- [Messages](https://mozex.dev/docs/anthropic-php/v1/usage/messages)
- [Streaming](https://mozex.dev/docs/anthropic-php/v1/usage/streaming)
- [Tool Use](https://mozex.dev/docs/anthropic-php/v1/usage/tool-use)
- [Thinking](https://mozex.dev/docs/anthropic-php/v1/usage/thinking)
- [Server Tools](https://mozex.dev/docs/anthropic-php/v1/usage/server-tools)
- [Citations](https://mozex.dev/docs/anthropic-php/v1/usage/citations)
- [Token Counting](https://mozex.dev/docs/anthropic-php/v1/usage/token-counting)
- [Models](https://mozex.dev/docs/anthropic-php/v1/usage/models)
- [Batches](https://mozex.dev/docs/anthropic-php/v1/usage/batches)
- [Completions](https://mozex.dev/docs/anthropic-php/v1/usage/completions)
- [Files](https://mozex.dev/docs/anthropic-php/v1/usage/files)
- [Raw Requests](https://mozex.dev/docs/anthropic-php/v1/usage/raw-requests)

### Reference

- [Configuration](https://mozex.dev/docs/anthropic-php/v1/reference/configuration)
- [Error Handling](https://mozex.dev/docs/anthropic-php/v1/reference/error-handling)
- [Meta Information](https://mozex.dev/docs/anthropic-php/v1/reference/meta-information)
- [Testing](https://mozex.dev/docs/anthropic-php/v1/reference/testing)