# Completions

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

---

> **Deprecated.** The API now rejects Text Completions requests on current models: a request to `/v1/complete` returns a 400 saying the endpoint has been deprecated and pointing to `/v1/messages`. Use the [Messages API](https://mozex.dev/docs/anthropic-php/v1/usage/messages) instead. It supports every current model, multi-turn conversations, tool use, thinking, and the rest of the API's features.

The Completions resource stays in the package for code that still references it. It's marked `@deprecated`, so IDEs and `phpstan/phpstan-deprecation-rules` flag every call to `completions()`. The examples below show its request and response shapes; they use `claude-2.1`, a retired model, and don't run against today's API.

## Creating a completion

```php
$response = $client->completions()->create([
    'model' => 'claude-2.1',
    'prompt' => '\n\nHuman: Hello, Claude\n\nAssistant:',
    'max_tokens_to_sample' => 100,
    'temperature' => 0,
]);

$response->type;       // 'completion'
$response->id;         // 'compl_01EKm5HZ9y6khqaSZjsX44fS'
$response->completion; // ' Hello! Nice to meet you.'
$response->stop_reason; // 'stop_sequence'
$response->model;      // 'claude-2.1'
$response->stop;       // '\n\nHuman:'
$response->log_id;     // 'compl_01EKm5HZ9y6khqaSZjsX44fS'

$response->toArray(); // ['id' => 'compl_01EKm5HZ9y6khqaSZjsX44fS', ...]
```

Note the prompt format: the Text Completions API uses a specific `\n\nHuman:` / `\n\nAssistant:` turn structure rather than a messages array.

## Streamed completions

```php
$stream = $client->completions()->createStreamed([
    'model' => 'claude-2.1',
    'prompt' => 'Hi',
    'max_tokens_to_sample' => 70,
]);

foreach ($stream as $response) {
    echo $response->completion;
}
// 'I' ' am' ' very' ' excited' ...
```

Each iteration gives you the next chunk of the completion text.

## Moving to Messages

A completion prompt maps to a single user message, and `max_tokens_to_sample` becomes `max_tokens`. Leave `temperature` out: current models return a 400 for it.

```php
$response = $client->messages()->create([
    'model' => 'claude-sonnet-5-5',
    'max_tokens' => 100,
    'messages' => [
        ['role' => 'user', 'content' => 'Hello, Claude'],
    ],
]);

foreach ($response->content as $block) {
    if ($block->type === 'text') {
        echo $block->text; // 'Hello! How can I help you today?'
    }
}
```

---

For the full specification, see the [Text Completions API reference](https://platform.claude.com/docs/en/api/completions/create) on the Anthropic docs.

---

## 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)