Download the PHP package talleu/cohere-php-client without Composer
On this page you can find all versions of the php package talleu/cohere-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download talleu/cohere-php-client
More information about talleu/cohere-php-client
Files in talleu/cohere-php-client
Package cohere-php-client
Short Description PHP client to interact with Cohere API
License MIT
Informations about the package cohere-php-client
Cohere PHP Client
A PHP client to interact with the Cohereยฎ API, designed to be framework-agnostic, simple to use, and fully compatible with PSR-18.
This package provides an easy and structured way to use Cohere's powerful language models โ for embeddings, chat, classification, tokenization, and more โ in any PHP project.
Features ๐ ๏ธ
- โ Support for Cohere API v1/v2 endpoints (chat, embed, classify, tokenize, etc.)
- โ Compatible with any PSR-18 HTTP Client
- โ File upload and multipart support
- โ Developer-friendly DTOs and response builders
- โ Easily extendable with your own endpoints
Requirements โ๏ธ
- PHP 8.2 or higher
- Composer
- A PSR-18 compatible HTTP client ( e.g. Guzzle, Symfony HttpClient, HTTPlug clients)
Installation ๐
Install the library via Composer:
Then install your preferred HTTP client
Using Symfony HttpClient:
Using Guzzle:
Or another client implementing PSR18
Basic Usage ๐ฏ
Minimal example
Or to simple chats with LLM
Authentication ๐
You can pass the API key directly in the http client:
Or use an environment variable (recommended):
Available Endpoints ๐
The following endpoints are supported:
| Endpoint | Class | Description |
|---|---|---|
v2/embed |
Embed |
Generate embeddings from input text |
v2/chat |
Chat |
Perform conversational chat with a LLM |
v1/classify |
Classify |
Text classification based on custom labels |
v1/tokenize |
Tokenize |
Token-level breakdown of input text |
v1/detokenize |
Detokenize |
De-tokenify tokens to text |
v1/connectors |
Connector |
Cohere connectors |
v1/embed-jobs |
EmbedJob |
Async embed jobs |
v2/rerank |
Rerank |
Retrieve Cohere available models |
v1/models |
Model |
Produces an ordered array with text |
v1/datasets |
Dataset |
Create a dataset by uploading a file, retrieve datasets |
v1/finetuning |
FineTuning |
Trains, deploy, list datasets |
You can access them via:
Then you can use it simple :
Each endpoint returns a strongly typed DTO with the result of the API call.
To send a request without using provided resources, you can use directly the CohereClient sendRequesst() method
๐ Documentation by endpoints
- Embedding
- Chat Completion
- Rerank
- Model
- Connector
- Classify
- Fine Tuning
- Dataset
- Embed jobs
- Tokenize
- Detokenize
- A tutorial for Fine-tune and Classify a dataset
Documentation ๐
- ๐ง Cohere official docs: https://docs.cohere.com
- ๐ API Reference: https://docs.cohere.com/reference
- ๐ฆ This PHP client wraps the API endpoints in a friendly OO API with typed DTOs.
Contributing ๐ค
PRs are welcome! If youโd like to add support for more endpoints, improve tests or add features, feel free to open an issue or submit a PR.
All versions of cohere-php-client with dependencies
ext-json Version *
php-http/discovery Version ^1.20
psr/http-client-implementation Version *
psr/http-factory-implementation Version *
psr/http-client Version ^1.0
psr/http-message Version ^2.0
psr/http-factory Version ^1.1
nyholm/psr7 Version ^1.8
php-http/multipart-stream-builder Version ^1.4