# Completions

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

---

> **Deprecated.** The API now rejects Text Completions requests on current models with a 400 saying the endpoint has been deprecated. Use the [Messages API](https://mozex.dev/docs/anthropic-laravel/v1/usage/messages) instead.

`Anthropic::completions()` stays for code that still references it. The resource behind it is marked `@deprecated`, so PHPStan's deprecation rules flag the `create()` and `createStreamed()` calls chained on it, through the facade too. The facade's own `completions()` can't carry the deprecation in its `@method` docblock, so an IDE may not strike it through; search your code for `Anthropic::completions(` when you move off it.

The examples below show the request and response shapes. They use `claude-2.1`, a retired model, and don't run against today's API.

## Creating a completion

```php
use Anthropic\Laravel\Facades\Anthropic;

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

$response->completion;  // ' Hello! Nice to meet you.'
$response->stop_reason; // 'stop_sequence'
$response->model;       // 'claude-2.1'
```

The prompt format uses specific `\n\nHuman:` / `\n\nAssistant:` turn markers rather than a messages array.

## Streamed completions

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

foreach ($stream as $response) {
    echo $response->completion;
}
```

## Moving to Messages

The prompt becomes a user message, and `max_tokens_to_sample` becomes `max_tokens`. Leave `temperature` out: current models return a 400 for it.

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

collect($response->content)->firstWhere('type', 'text')?->text;
```

---

For the full request and response specification, see the [Completions page in the PHP docs](https://mozex.dev/docs/anthropic-php/v1/usage/completions) or 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-laravel/v1)
- [AI Integration](https://mozex.dev/docs/anthropic-laravel/v1/ai-integration)
- [Support Us](https://mozex.dev/docs/anthropic-laravel/v1/support-us)
- [Requirements](https://mozex.dev/docs/anthropic-laravel/v1/requirements)
- [Changelog](https://mozex.dev/docs/anthropic-laravel/v1/changelog)
- [Contributing](https://mozex.dev/docs/anthropic-laravel/v1/contributing)
- [Questions & Issues](https://mozex.dev/docs/anthropic-laravel/v1/questions-and-issues)
- [About Mozex](https://mozex.dev/docs/anthropic-laravel/v1/about)

### Usage

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

### Reference

- [Configuration](https://mozex.dev/docs/anthropic-laravel/v1/reference/configuration)
- [Error Handling](https://mozex.dev/docs/anthropic-laravel/v1/reference/error-handling)
- [Meta Information](https://mozex.dev/docs/anthropic-laravel/v1/reference/meta-information)
- [Testing](https://mozex.dev/docs/anthropic-laravel/v1/reference/testing)
- [Using alongside laravel/ai](https://mozex.dev/docs/anthropic-laravel/v1/reference/laravel-ai)
- [Diagnostics](https://mozex.dev/docs/anthropic-laravel/v1/reference/diagnostics)