PHPackages                             llm-speak/anthropic-claude - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. llm-speak/anthropic-claude

ActiveLibrary[API Development](/categories/api)

llm-speak/anthropic-claude
==========================

A Laravel package for integrating Anthropic Claude into LLMSpeak

0.4.1(9mo ago)08MITPHPPHP ^8.2

Since Jul 2Pushed 9mo agoCompare

[ Source](https://github.com/projectsaturnstudios/llm-speak-anthropic)[ Packagist](https://packagist.org/packages/llm-speak/anthropic-claude)[ RSS](/packages/llm-speak-anthropic-claude/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

LLMSpeak Anthropic Claude
=========================

[](#llmspeak-anthropic-claude)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP](https://camo.githubusercontent.com/0f16581d1180dbfd4c0e13166ec1267d4ad2f2fab8281ea6d6b284cf5c65d921/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c75652e737667)](https://php.net/releases/)[![Laravel](https://camo.githubusercontent.com/906dea2eb7060f4769da2f105c19b13c8e426284048c7217e23102fb572d64a8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825374331312e7825374331322e782d7265642e737667)](https://laravel.com)[![Total Downloads](https://camo.githubusercontent.com/a025673ccf02d9fc9d8130ff3d1bdcad212af0cb8f5a1d2a4f498bc4008b737f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6c6d2d737065616b2f616e7468726f7069632d636c617564652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm-speak/anthropic-claude)

**LLMSpeak Anthropic Claude** is a Laravel package that provides a fluent, Laravel-native interface for integrating with Anthropic's Claude AI models. Built as part of the LLMSpeak ecosystem, it offers seamless integration with Laravel applications through automatic service discovery and expressive request builders.

> **Note:** This package is part of the larger [LLMSpeak ecosystem](https://github.com/projectsaturnstudios/llm-speak). For universal provider switching and standardized interfaces, check out the [LLMSpeak Core](https://github.com/projectsaturnstudios/llm-speak) package.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Get Started](#get-started)
- [Usage](#usage)
    - [Basic Request](#basic-request)
    - [Fluent Request Building](#fluent-request-building)
    - [System Instructions](#system-instructions)
    - [Tool Calling](#tool-calling)
    - [Streaming Responses](#streaming-responses)
    - [Advanced Configuration](#advanced-configuration)
    - [Response Handling](#response-handling)
    - [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Features
--------

[](#features)

- **🚀 Laravel Native**: Full Laravel integration with automatic service discovery
- **🔧 Fluent Interface**: Expressive request builders with method chaining
- **📊 Laravel Data**: Powered by Spatie Laravel Data for robust data validation
- **🛠️ Tool Support**: Complete function calling capabilities
- **💨 Streaming**: Support for real-time streaming responses
- **🎯 Type Safety**: Full PHP 8.2+ type declarations and IDE support
- **🔐 Secure**: Built-in API key management and request validation

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.2+](https://php.net/releases/) and Laravel 10.x/11.x/12.x**

Install the package via [Composer](https://getcomposer.org/):

```
composer require llm-speak/anthropic-claude
```

The package will automatically register itself via Laravel's package discovery.

### Environment Configuration

[](#environment-configuration)

Add your Anthropic API key to your `.env` file:

```
ANTHROPIC_API_KEY=your_api_key_here
```

> **Note:** The package currently uses Anthropic API version `2023-06-01` (hardcoded).

Usage
-----

[](#usage)

### Basic Request

[](#basic-request)

The simplest way to send a message to Claude:

```
use LLMSpeak\Anthropic\ClaudeMessageRequest;

$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: [
        ['role' => 'user', 'content' => 'Hello, Claude!']
    ]
);

$response = $request->post();

echo $response->getTextContent(); // "Hello! How can I assist you today?"
```

### Fluent Request Building

[](#fluent-request-building)

Build complex requests using the fluent interface:

```
use LLMSpeak\Anthropic\ClaudeMessageRequest;

$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: [
        ['role' => 'user', 'content' => 'Explain quantum computing']
    ]
)
->setMaxTokens(1000)
->setTemperature(0.7)
->setSystem('You are a helpful physics professor.')
->setTopK(50)
->setTopP(0.9);

$response = $request->post();

// Access response properties
echo $response->id;              // msg_01ABC123...
echo $response->model;           // claude-3-5-sonnet-20241022
echo $response->stop_reason;     // end_turn
echo $response->getTotalTokens(); // 850
```

### Batch Configuration

[](#batch-configuration)

Set multiple parameters at once:

```
$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: $messages
)->setMultiple([
    'max_tokens' => 1500,
    'temperature' => 0.8,
    'top_k' => 40,
    'stop_sequences' => ['Human:', 'Assistant:']
]);
```

### System Instructions

[](#system-instructions)

Claude supports rich system instructions for context and behavior:

```
$systemPrompt = "You are Claude, an AI assistant created by Anthropic. " .
                "You are helpful, harmless, and honest. " .
                "Provide detailed explanations with examples.";

$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: [
        ['role' => 'user', 'content' => 'Explain machine learning']
    ]
)->setSystem($systemPrompt);

$response = $request->post();
```

### Tool Calling

[](#tool-calling)

Enable Claude to use external functions and tools:

```
$tools = [
    [
        'name' => 'get_weather',
        'description' => 'Get current weather for a location',
        'input_schema' => [
            'type' => 'object',
            'properties' => [
                'location' => [
                    'type' => 'string',
                    'description' => 'City and state/country'
                ],
                'unit' => [
                    'type' => 'string',
                    'enum' => ['celsius', 'fahrenheit'],
                    'description' => 'Temperature unit'
                ]
            ],
            'required' => ['location']
        ]
    ]
];

$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: [
        ['role' => 'user', 'content' => 'What\'s the weather in San Francisco?']
    ]
)
->setTools($tools)
->setToolChoice('auto');

$response = $request->post();

// Check if tools were used
if ($response->usedTools()) {
    $toolCalls = $response->getToolCalls();
    foreach ($toolCalls as $toolCall) {
        echo "Tool: {$toolCall['name']}\n";
        echo "Input: " . json_encode($toolCall['input']) . "\n";
    }
}
```

### Streaming Responses

[](#streaming-responses)

Enable real-time streaming for long responses:

```
$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: [
        ['role' => 'user', 'content' => 'Write a long story about space exploration']
    ]
)
->setStream(true)
->setMaxTokens(2000);

$response = $request->post();

// Stream will be handled by the MessagesEndpoint
// Check response for streaming data format
```

### Advanced Configuration

[](#advanced-configuration)

Configure advanced parameters for fine-tuned control:

```
$request = new ClaudeMessageRequest(
    model: 'claude-3-5-sonnet-20241022',
    messages: $conversationHistory
)
->setMaxTokens(4000)
->setTemperature(0.6)
->setTopK(60)
->setTopP(0.95)
->setStopSequences(['[END]', '###'])
->setMetadata([
    'user_id' => 'user_123',
    'session_id' => 'session_456'
])
->setServiceTier('standard_only');

$response = $request->post();
```

Response Handling
-----------------

[](#response-handling)

Access rich response data:

```
$response = $request->post();

// Basic response info
$messageId = $response->id;
$modelUsed = $response->model;
$completionReason = $response->stop_reason;

// Content access
$textContent = $response->getTextContent();
$allContent = $response->content; // Raw content array

// Token usage
$inputTokens = $response->getInputTokens();
$outputTokens = $response->getOutputTokens();
$totalTokens = $response->getTotalTokens();

// Completion status
$isComplete = $response->completedNaturally();
$hitTokenLimit = $response->reachedTokenLimit();

// Convert to array for storage/processing
$responseArray = $response->toArray();
```

Testing
-------

[](#testing)

The package provides testing utilities for mocking Anthropic responses:

```
use LLMSpeak\Anthropic\ClaudeMessageRequest;
use LLMSpeak\Anthropic\ClaudeMessageResponse;

// Create a mock response
$mockResponse = new ClaudeMessageResponse(
    id: 'msg_test_123',
    type: 'message',
    role: 'assistant',
    content: [
        ['type' => 'text', 'text' => 'Test response']
    ],
    model: 'claude-3-5-sonnet-20241022',
    stop_reason: 'end_turn',
    stop_sequence: null,
    usage: [
        'input_tokens' => 10,
        'output_tokens' => 15
    ]
);

// Test your application logic with the mock
$this->assertEquals('Test response', $mockResponse->getTextContent());
```

Credits
-------

[](#credits)

- [Project Saturn Studios](https://github.com/projectsaturnstudios)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

**Part of the LLMSpeak Ecosystem** - Made with ADHD by [Project Saturn Studios](https://projectsaturnstudios.com)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance57

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

4

Last Release

285d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2169021b88d520bd58d9a37f51fa55058af7adbf7362c8cade65b261d644874c?d=identicon)[projectsaturnstudios](/maintainers/projectsaturnstudios)

---

Top Contributors

[![projectsaturnstudios](https://avatars.githubusercontent.com/u/10563160?v=4)](https://github.com/projectsaturnstudios "projectsaturnstudios (7 commits)")

### Embed Badge

![Health badge](/badges/llm-speak-anthropic-claude/health.svg)

```
[![Health](https://phpackages.com/badges/llm-speak-anthropic-claude/health.svg)](https://phpackages.com/packages/llm-speak-anthropic-claude)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
