Download the PHP package tigusigalpa/monica-api-php without Composer
On this page you can find all versions of the php package tigusigalpa/monica-api-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tigusigalpa/monica-api-php
More information about tigusigalpa/monica-api-php
Files in tigusigalpa/monica-api-php
Package monica-api-php
Short Description PHP client library for Monica API Platform - unified access to multiple AI models
License MIT
Homepage https://github.com/tigusigalpa/monica-api-php
Informations about the package monica-api-php
Monica AI API PHP Client/SDK
A powerful and elegant PHP client (SDK) library for Monica API Platform - your unified gateway to multiple AI models from leading providers.
π Features
- Unified API Access: Single interface to multiple AI providers (OpenAI, Anthropic, Google, DeepSeek, Meta, Grok, NVIDIA, Mistral)
- Latest AI Models: Support for cutting-edge models including GPT-5, Claude 4, and Gemini 2.5
- Image Generation: Support for FLUX, Stable Diffusion, DALLΒ·E, Playground, and Ideogram models
- Type Safety: Full PHP 8.1+ type declarations and strict typing
- Rich Documentation: Comprehensive PHPDoc comments and examples
- Error Handling: Robust exception handling with detailed error information
- Flexible Configuration: Support for all major AI model parameters
- Laravel Ready: Perfect integration with Laravel applications
- PSR-4 Autoloading: Modern PHP standards compliance
π Supported AI Models
Provider | Model | Description | Image Input Support |
---|---|---|---|
OpenAI | gpt-5 |
GPT-5 (Latest flagship model) | β Yes |
gpt-4.1 |
GPT-4.1 (Main model) | β Yes | |
gpt-4.1-mini |
GPT-4.1 Mini (Lightweight) | β Yes | |
gpt-4.1-nano |
GPT-4.1 Nano (Ultra-light) | β Yes | |
gpt-4o |
GPT-4o (With image support) | β Yes | |
gpt-4o-mini |
GPT-4o Mini (Lightweight) | β Yes | |
Anthropic | claude-sonnet-4-20250514 |
Claude 4 Sonnet | β Yes |
claude-opus-4-20250514 |
Claude 4 Opus | β Yes | |
claude-3-7-sonnet-latest |
Claude 3.7 Sonnet | β Yes | |
claude-3-5-sonnet-latest |
Claude 3.5 Sonnet | β Yes | |
claude-3-5-haiku-latest |
Claude 3.5 Haiku | β No | |
gemini-2.5-pro |
Gemini 2.5 Pro Preview | β Yes | |
gemini-2.5-flash |
Gemini 2.5 Flash | β Yes | |
DeepSeek | deepseek-reasoner |
DeepSeek V3 Reasoner | β No |
deepseek-chat |
DeepSeek V3 Chat | β No | |
Meta | meta-llama/llama-3-8b-instruct |
Meta: Llama 3 8B Instruct | β No |
meta-llama/llama-3.1-8b-instruct |
Meta: Llama 3.1 8B Instruct | β No | |
Grok | x-ai/grok-3-beta |
Grok 3 Beta | β No |
NVIDIA | nvidia/llama-3.1-nemotron-70b-instruct |
NVIDIA: Llama 3.1 Nemotron 70B | β No |
Mistral | mistralai/mistral-7b-instruct |
Mistral: Mistral 7B Instruct | β No |
π Note: Only OpenAI, Anthropic (Claude), and Google (Gemini) models support image input in chat requests. Other providers will return an error if images are included in the request.
π¨ Supported Image Generation Models
FLUX Models
- FLUX.1 Schnell: Entry-level model optimized for speed and efficiency
- FLUX.1 Dev: Developer-focused variant with enhanced customization options
- FLUX.1 Pro: Professional-grade model with highest quality output
Stable Diffusion Models
- Stable Diffusion XL 1.0: Efficient image generation with good quality
- Stable Diffusion 3: Advanced model with better prompting and higher quality
- Stable Diffusion 3.5 Large: Latest model with exceptional detail and realism
DALLΒ·E Models
- DALLΒ·E 3: Highly detailed and photorealistic images with superior understanding
Playground Models
- Playground V2.5: Cost-effective solution with strong artistic style interpretation
Ideogram Models
- Ideogram V2: Exceptional text rendering capabilities, ideal for logos and typography
π Installation
Install via Composer:
π§ Requirements
- PHP 8.1 or higher
- Guzzle HTTP 7.0+
- Monica AI API key (Get yours here)
π Quick Start
π Usage Examples
Basic Chat Completion
Advanced Configuration
Conversation with Multiple Messages
Understanding Chat Methods: chat()
vs chatWithMessages()
MonicaAPI provides two main methods for chat interactions, each designed for different use cases:
Method Comparison
Feature | chat() |
chatWithMessages() |
---|---|---|
Input Type | string (simple text) |
ChatMessage[] (array of messages) |
Use Case | Single message | Multiple messages in one request |
Message Structure | β Auto-creates user message | β Full control over message roles |
Image Support | β Text only | β Multimodal (text + images) |
System Messages | β Via options parameter | β As separate ChatMessage objects |
Complexity | π’ Simple and quick | π‘ More setup required |
Flexibility | π‘ Limited customization | π’ Full control over message structure |
Best For | Quick queries, testing | Complex messages, image analysis |
When to Use chat()
Perfect for simple, standalone interactions:
When to Use chatWithMessages()
Essential for complex message structures:
Migration Guide
If you need to upgrade from chat()
to chatWithMessages()
:
Chat with Images (Vision Models)
Vision-capable models like GPT-5 and GPT-4o can analyze and discuss images. Here are examples of how to upload images to chat:
Upload Image from File
Upload Image from URL
Upload Multiple Images
Upload Image from Base64
Advanced Image Chat Example
Working with Image Details
Supported Vision Models
The following models support image analysis:
- GPT-5: Most advanced image analysis and understanding capabilities
- GPT-4o: Excellent for detailed image analysis and understanding
- GPT-4o Mini: Faster, cost-effective option for basic image tasks
Creating Messages from Array Data
You can create ChatMessage
instances directly from array data using the fromArray()
method. This is particularly
useful when working with pre-structured message data or when integrating with existing systems that use
OpenAI-compatible message formats.
Basic Usage
Multimodal Messages with Mixed Content
Working with Conversation Arrays
Helper Function for Batch Processing
Supported Array Structure
The fromArray()
method supports the following message structure:
π¨ Image Generation Usage
Simple Image Generation
Advanced Image Generation
Model-Specific Examples
DALLΒ·E 3 with Quality Options
Ideogram V2 for Text and Logos
Playground V2.5 with Multiple Outputs
Model Management
Error Handling
Working with Response Data
π§ Configuration Options
Chat Completion Parameters
Parameter | Type | Description | Range |
---|---|---|---|
system |
string | System message to set AI behavior | - |
temperature |
float | Controls randomness in responses | 0.0 - 2.0 |
max_tokens |
int | Maximum tokens in response | 1 - model limit |
top_p |
float | Nucleus sampling parameter | 0.0 - 1.0 |
frequency_penalty |
float | Reduces repetition of frequent tokens | -2.0 - 2.0 |
presence_penalty |
float | Reduces repetition of any tokens | -2.0 - 2.0 |
Example with All Parameters
π Laravel Integration
Service Provider Registration
Service Provider Example
Configuration
Environment Variables
Controller Example
π§ͺ Testing
Run the test suite:
Run with coverage:
π API Reference
MonicaClient
Constructor
Methods
chat(string $message, array $options = []): ChatCompletionResponse
chatWithMessages(ChatMessage[] $messages, array $options = []): ChatCompletionResponse
generateImage(ImageGeneration $imageGeneration): ImageGenerationResponse
generateImageSimple(string $model, string $prompt, array $options = []): ImageGenerationResponse
setModel(string $model): void
getModel(): string
isModelSupported(string $model): bool
static getSupportedModels(): array
static getModelsByProvider(string $provider): array
static getAllModelIds(): array
static getSupportedImageModels(): array
ChatMessage
Static Constructors
ChatMessage::system(string $content, ?string $name = null): ChatMessage
ChatMessage::user(string $content, ?string $name = null): ChatMessage
ChatMessage::assistant(string $content, ?string $name = null): ChatMessage
ChatMessage::userWithImage(string $content, string $imageUrl): ChatMessage
ChatMessage::userWithImages(string $content, array $imageUrls): ChatMessage
ChatMessage::fromArray(array $data): ChatMessage
Methods
getRole(): string
getContent(): string
getName(): ?string
isSystem(): bool
isUser(): bool
isAssistant(): bool
hasImages(): bool
getImages(): array
addImageFromFile(string $filePath, string $detail = 'auto'): self
addImageFromUrl(string $url, string $detail = 'auto'): self
addImageFromBase64(string $base64Data, string $mimeType, string $detail = 'auto'): self
toArray(): array
ChatCompletionResponse
Methods
getContent(): string
getRole(): string
getFinishReason(): ?string
getTotalTokens(): int
getPromptTokens(): int
getCompletionTokens(): int
isComplete(): bool
wasTruncated(): bool
wasFiltered(): bool
getFirstChoice(): ?array
getFirstChoiceAsMessage(): ?ChatMessage
getAllChoices(): array
ImageGeneration
Constructor
Methods
getModel(): string
getPrompt(): string
setNegativePrompt(string $negativePrompt): self
setNumOutputs(int $numOutputs): self
setSize(string $size): self
setSeed(int $seed): self
setSteps(int $steps): self
setGuidance(float $guidance): self
setCfgScale(float $cfgScale): self
setQuality(string $quality): self
setStyle(string $style): self
setAspectRatio(string $aspectRatio): self
setMagicPromptOption(string $option): self
setStyleType(string $styleType): self
setSafetyTolerance(int $tolerance): self
static isModelSupported(string $model): bool
static getSupportedModels(): array
toArray(): array
ImageGenerationResponse
Methods
getImageUrls(): array
getFirstImageUrl(): ?string
saveFirstImage(string $filePath): bool
saveAllImages(string $directory, string $prefix = 'image_', string $extension = 'png'): array
getImageCount(): int
π Changelog
[Unreleased]
Added
- GPT-5 Support: Added support for OpenAI's latest flagship model
gpt-5
- Full chat completion capabilities with advanced reasoning
- Enhanced image analysis and multimodal understanding
- Updated default model examples to showcase GPT-5
- Added GPT-5 to supported vision models list
Changed
- Updated Quick Start example to use GPT-5 as the default model
- Enhanced Laravel integration examples with GPT-5 configuration
- Updated model comparison tables to highlight GPT-5 capabilities
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Clone the repository
- Install dependencies:
composer install
- Run tests:
composer test
- Check code style:
composer cs-check
- Fix code style:
composer cs-fix
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Links
π¬ Support
If you have any questions or need help, please:
- Check the documentation
- Search existing GitHub issues
- Create a new issue if needed
π Acknowledgments
- Monica API Platform for providing the unified AI API
- All the AI providers (OpenAI, Anthropic, Google, etc.) for their amazing models
- The PHP community for excellent tools and libraries