getstream / getstream-php
PHP SDK for GetStream API
Requires
- php: ^8.1
- ext-curl: *
- ext-json: *
- firebase/php-jwt: ^7.0
- guzzlehttp/guzzle: ^7.0
- vlucas/phpdotenv: ^5.0
Requires (Dev)
- brianium/paratest: >=7.2 <7.9
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.7
- dev-master
- v6.0.0
- v5.0.0
- v4.2.0
- v4.1.0
- v4.0.0
- v4.0.0-beta.1
- v3.0.0
- v2.1.0
- v2.0.2
- v2.0.0
- v1.0.0
- v0.0.3
- v0.0.2
- v0.0.1
- dev-fix/ci-release-flow
- dev-FEEDS-1350
- dev-release-5.0.0
- dev-feature/cha-2563-retention-policy-endpoints
- dev-release-4.2.0
- dev-release-4.1.0
- dev-FEEDS-1303
- dev-cha-2587_migration-docs
- dev-release-4.0.0
- dev-pla/release-v4.0.0
- dev-cha-1578_openapi-refactor-codegen
- dev-release-3.0.0
- dev-FEEDS-1149
- dev-release-2.1.0
- dev-FEEDS-852
- dev-release-2.0.2
- dev-FEEDS-863
- dev-release-2.0.0
- dev-package
- dev-release-v1.0.0
- dev-sdk-update
- dev-version-bug
- dev-release-v0.0.3
- dev-object_serial
- dev-date_bug
- dev-moderation
- dev-release-v0.0.2
- dev-release-v0.0.1
This package is auto-updated.
Last update: 2026-04-01 16:46:41 UTC
README
A PHP SDK for the GetStream API.
Installation
Install via Composer:
composer require getstream/getstream-php
Migrating from stream-chat-php?
If you are currently using stream-chat-php, we have a detailed migration guide with side-by-side code examples for common Chat use cases. See the Migration Guide.
Configuration
Copy .env.example to .env and configure:
cp .env.example .env
Required environment variables:
STREAM_API_KEY=your_api_key_here STREAM_API_SECRET=your_api_secret_here STREAM_BASE_URL=https://chat.stream-io-api.com
Code Generation
Generate API methods from OpenAPI spec:
./generate.sh
Testing
Run tests:
# Run all tests make test # Run unit tests only make test-unit # Run integration tests (requires API credentials) make test-integration
Usage
Basic Setup
<?php require_once 'vendor/autoload.php'; use GetStream\ClientBuilder; $client = ClientBuilder::fromEnv()->build(); $feed = $client->feed('user', 'john-doe');
Working with Activities
use GetStream\GeneratedModels\AddActivityRequest; // Create an activity $activity = new AddActivityRequest( actor: 'user:john', verb: 'post', object: 'message:123', text: 'Hello World!' ); $response = $client->addActivity($activity); // Access response data directly $createdActivity = $response->activity; echo "Activity ID: " . $createdActivity->id; // Or access HTTP metadata echo "Status: " . $response->getStatusCode(); echo "Duration: " . $response->duration;
Models
Note: When constructing models directly, always use named arguments (e.g.
new Message(text: 'hello')). Positional argument usage is not supported and may break across SDK updates as parameter order is not guaranteed.
Automatic JSON Parsing
Generated models automatically handle JSON parsing and serialization:
// Models parse JSON based on constructor types $response = $client->addActivity($request); $activity = $response->activity; // Fully typed object
Custom JSON Key Mapping
Override field names using the JsonKey attribute:
use GetStream\GeneratedModels\JsonKey; class CustomModel extends BaseModel { public function __construct( #[JsonKey('fids')] public ?array $feedIds = null, // Maps to "fids" instead of "feed_ids" ) {} }
Response Access
$response = $client->addActivity($request); // Direct access $activity = $response->activity; // HTTP metadata $statusCode = $response->getStatusCode(); $duration = $response->duration;
Code Generation
Generate models and clients from OpenAPI spec:
./generate.sh
This creates clean, typed models with automatic JSON handling - no boilerplate code needed.
Development
Release Workflow
Releases are automated when a pull request is merged into main or master.
- PR titles must follow Conventional Commit format (for example:
feat: ...,fix: ...). - Ticket prefix is required in the subject:
type: [FEEDS-1234] description. - Keep the commit type first so release automation can parse it.
- Version bump is derived from PR title/body:
feat:=> minorfix:orbug:=> patchfeat!:/fix!:/BREAKING CHANGE=> major
- Non-release types like
chore:,docs:,test:do not create a release. - The release workflow updates
composer.jsonandsrc/Constant.php, pushes a tag, creates a GitHub release, and triggers Packagist.
Examples:
feat: [FEEDS-1350] add feed retention endpointfix: [FEEDS-1402] handle missing reaction idfeat!: [FEEDS-1410] remove deprecated follow API
Linting and Code Quality
# Run all available linting checks make lint # Run PHPStan static analysis only make phpstan # Fix code style issues (requires php-cs-fixer) make cs-fix # Run comprehensive quality checks (lint + tests) make quality
Testing
# Run all tests make test # Run unit tests only make test-unit # Run integration tests make test-integration