PHP code example of spectracost / sdk

1. Go to this page and download the library: Download spectracost/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spectracost / sdk example snippets



use Spectracost\Spectracost;
use Spectracost\Options;
use Spectracost\Openai\ChatRequest;
use Spectracost\Openai\Message;

$sc = new Spectracost(new Options(
    apiKey: 'sprc_...',
    openaiApiKey: 'sk-...',
    team: 'search',
));

$response = $sc->openaiChat(new ChatRequest(
    model: 'gpt-4o-mini',
    messages: [new Message('user', 'Say hello!')],
    maxTokens: 50,
));

echo $response->firstMessage();


use Spectracost\Spectracost;
use Spectracost\Options;
use Spectracost\Anthropic\MessagesRequest;
use Spectracost\Anthropic\Message;

$sc = new Spectracost(new Options(
    apiKey: 'sprc_...',
    anthropicApiKey: 'sk-ant-...',
    team: 'support',
));

$response = $sc->anthropicMessages(new MessagesRequest(
    model: 'claude-haiku-4-5-20251001',
    maxTokens: 50,
    messages: [new Message('user', 'Say hello!')],
));

echo $response->firstText();