r5dy1n/straico-php

PHP SDK for Straico API - Unified generative AI platform

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/r5dy1n/straico-php

v1.0.0 2025-12-31 04:03 UTC

This package is auto-updated.

Last update: 2025-12-31 04:08:48 UTC


README

A comprehensive PHP SDK for the Straico API - a unified platform for generative AI capabilities including text generation, image creation, chat, RAG (Retrieval Augmented Generation), and autonomous agents.

Features

  • Simple and intuitive API interface
  • Support for all Straico API endpoints (v0, v1, v2)
  • Environment variable configuration
  • PSR-4 autoloading
  • Comprehensive error handling
  • Full type hinting
  • File upload support
  • Multi-version API support

Requirements

  • PHP 7.4 or higher
  • Composer

Installation

Install via Composer:

composer require r5dy1n/straico-php

Configuration

API Key

Get your API key from Straico. You can provide it in two ways:

  1. Environment Variable (recommended):
export STRAICO_API_KEY="your-api-key-here"
  1. Constructor Parameter:
$straico = new \Straico\Straico('your-api-key-here');

Usage

Initialize Client

<?php

require_once 'vendor/autoload.php';

use Straico\Straico;
use Straico\Exceptions\StraicoException;

// Using environment variable
$straico = new Straico();

// Or with API key parameter
$straico = new Straico('your-api-key-here');

User Information

Get current user account details including coins, plan, and name:

try {
    $user = $straico->user();
    print_r($user);
} catch (StraicoException $e) {
    echo "Error: " . $e->getMessage();
}

Available Models

Retrieve list of available AI models with pricing and specifications:

// Get models (v0)
$models = $straico->models();

// Get models (v1)
$models = $straico->modelsV1();

// Get models (v2) - OpenAI-Compatible format
$models = $straico->modelsV2();

foreach ($models['data'] as $model) {
    echo $model['name'] . " - " . $model['pricing']['coins'] . " coins\n";
}

Get Specific Model

Get detailed information about a specific model:

$model = $straico->model('openai/gpt-4');
print_r($model);

Prompt Completion (Text Generation)

Generate text using AI models:

// Using v0 (default)
$response = $straico->promptCompletion(
    model: 'openai/gpt-4',
    message: 'Explain quantum computing in simple terms',
    options: []
);

// Using v1
$response = $straico->promptCompletionV1(
    model: 'openai/gpt-4',
    message: 'Explain quantum computing in simple terms',
    options: []
);

echo $response['choices'][0]['message']['content'];

With Additional Options

$response = $straico->promptCompletion(
    model: 'openai/gpt-4',
    message: 'Analyze this image and describe what you see',
    options: [
        'images' => ['path/to/image.jpg'],
        'display_transcripts' => true
    ]
);

With YouTube URL Analysis

$response = $straico->promptCompletion(
    model: 'anthropic/claude-3-opus',
    message: 'Summarize this video',
    options: [
        'youtube_urls' => ['https://youtube.com/watch?v=...'],
        'display_transcripts' => true
    ]
);

Chat Completion

Use chat-based models with conversation history:

// Using v0 (default)
$response = $straico->chatCompletion(
    model: 'openai/gpt-4',
    messages: [
        ['role' => 'system', 'content' => 'You are a helpful assistant.'],
        ['role' => 'user', 'content' => 'What is the capital of France?']
    ]
);

// Using v1
$response = $straico->chatCompletionV1(
    model: 'openai/gpt-4',
    messages: [
        ['role' => 'user', 'content' => 'Hello!']
    ]
);

// Using v2
$response = $straico->chatCompletionV2(
    model: 'openai/gpt-4',
    messages: [
        ['role' => 'user', 'content' => 'Hello!']
    ],
    options: [
        'temperature' => 0.7,
        'max_tokens' => 150
    ]
);

echo $response['choices'][0]['message']['content'];

File Upload

Upload files to use in other API calls:

$uploadResult = $straico->uploadFile('/path/to/document.pdf');
$fileId = $uploadResult['file_id'];
echo "File uploaded: $fileId\n";

Image Generation

Generate images from text descriptions:

$result = $straico->imageGeneration(
    model: 'openai/dall-e-3',
    description: 'A serene landscape with mountains and a lake at sunset',
    size: '1024x1024',
    variations: 1
);

$imageUrl = $result['data'][0]['url'];
echo "Generated image: $imageUrl\n";

RAG (Retrieval Augmented Generation)

Create RAG Instance

$rag = $straico->createRag(
    name: 'My Knowledge Base',
    description: 'Documentation and guides',
    files: [
        [
            'name' => 'document.pdf',
            'content' => base64_encode(file_get_contents('document.pdf'))
        ]
    ]
);

$ragId = $rag['id'];

List All RAGs

$rags = $straico->rags();

foreach ($rags as $rag) {
    echo $rag['name'] . " (ID: " . $rag['id'] . ")\n";
}

Get Specific RAG

$rag = $straico->rag('rag-id-here');
print_r($rag);

Update RAG with New Files

Add more files to an existing RAG:

$result = $straico->updateRag(
    ragId: 'rag-id-here',
    filePaths: [
        '/path/to/new-document.pdf',
        '/path/to/another-file.txt'
    ]
);

echo "RAG updated with " . $result['total_words'] . " words\n";

Query RAG with Prompt

// Basic query
$response = $straico->ragPromptCompletion(
    ragId: 'rag-id-here',
    model: 'openai/gpt-4',
    prompt: 'What does the documentation say about authentication?'
);

// With optional retriever parameters
$response = $straico->ragPromptCompletion(
    ragId: 'rag-id-here',
    model: 'openai/gpt-4',
    prompt: 'What does the documentation say about authentication?',
    options: [
        'search_type' => 'similarity',  // similarity, mmr, or similarity_score_threshold
        'k' => 4,                        // number of documents to return
        'fetch_k' => 20,                 // documents to pass to MMR algorithm
        'lambda_mult' => 0.5,            // diversity (0=max diversity, 1=min diversity)
        'score_threshold' => 0.7         // minimum relevance threshold
    ]
);

echo $response['data']['answer'];

// View references
foreach ($response['data']['references'] as $ref) {
    echo "Page {$ref['page']}: {$ref['page_content']}\n";
}

Delete RAG

$result = $straico->deleteRag('rag-id-here');

Agents

Create Agent

Create autonomous agents for task execution:

$agent = $straico->createAgent([
    'name' => 'Research Assistant',
    'description' => 'Helps with research tasks',
    'model' => 'openai/gpt-4',
    // Additional configuration...
]);

$agentId = $agent['_id'];

Query Agent

// Basic query
$response = $straico->agentPromptCompletion(
    agentId: 'agent-id-here',
    prompt: 'Research the latest developments in AI'
);

// With optional parameters
$response = $straico->agentPromptCompletion(
    agentId: 'agent-id-here',
    prompt: 'Research the latest developments in AI',
    options: [
        'search_type' => 'mmr',
        'k' => 5
    ]
);

echo $response['data']['answer'];

Error Handling

All methods throw StraicoException on errors:

use Straico\Exceptions\StraicoException;

try {
    $response = $straico->promptCompletion('openai/gpt-4', 'Hello');
} catch (StraicoException $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Code: " . $e->getCode() . "\n";
}

API Methods Reference

User

Method Description Version
user() Get user account information v0

Models

Method Description Version
models() List available AI models v0
modelsV1() List available AI models v1
modelsV2() List available AI models (OpenAI-compatible) v2
model($modelId) Get specific model information v2

Prompt Completion

Method Description Version
promptCompletion($model, $message, $options) Generate text completion v0
promptCompletionV1($model, $message, $options) Generate text completion v1

Chat Completion

Method Description Version
chatCompletion($model, $messages, $options) Chat-based completion v0
chatCompletionV1($model, $messages, $options) Chat-based completion v1
chatCompletionV2($model, $messages, $options) Chat-based completion v2

Files

Method Description Version
uploadFile($filePath) Upload a file v0

Images

Method Description Version
imageGeneration($model, $description, $size, $variations) Generate images v0

RAG

Method Description Version
createRag($name, $description, $files) Create RAG instance v0
rags() List all RAGs v0
rag($ragId) Get specific RAG v0
updateRag($ragId, $filePaths) Update RAG with new files v0
deleteRag($ragId) Delete RAG v0
ragPromptCompletion($ragId, $model, $prompt, $options) Query RAG v0

Agents

Method Description Version
createAgent($config) Create agent v0
agentPromptCompletion($agentId, $prompt, $options) Query agent v0

Official Documentation

For complete API documentation, visit:

License

MIT License

Support

For issues and questions:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.