PHP
Generate production-ready PHP SDKs from your OpenAPI specification
The Stainless PHP SDK generator creates idiomatic, type-safe PHP client libraries from your OpenAPI specification.
Example repositories:
Configuration
Section titled “Configuration”To generate a PHP SDK, add the php target to your Stainless configuration file:
targets: php: package_name: Acme composer_package_name: acme-org/acme-php edition: php.2025-10-08Common configuration options
Section titled “Common configuration options”targets: php: # package_name is used within the SDK (e.g., class AcmeClient { ... }) package_name: Acme
# composer_package_name is the Packagist installation name (e.g., composer require acme-org/acme-php) composer_package_name: acme-org/acme-php
# Specify the edition edition: php.2025-10-08
# Configure publishing publish: packagist: trueFor a complete list of configuration options, see the PHP target reference.
Editions
Section titled “Editions”Editions allow Stainless to make improvements to SDKs that aren’t backwards-compatible. You can explicitly opt in to new editions when you’re ready. See the SDK and config editions reference for more information.
php.2025-10-08
- Initial edition for PHP (used by default if no edition is specified)
Publishing to Packagist
Section titled “Publishing to Packagist”Publish your PHP SDK to Packagist for distribution.
Set the Composer package name in the Stainless config
Navigate to the targets section of your stainless config, and ensure it resembles the following.
targets: php: package_name: acme composer_package_name: 'acme-org/acme-php' # <- Packagist installation name publish: packagist: trueThe composer_package_name will appear in Packagist.
Make sure that the name follows the convention of the Composer specification,
which is roughly equivalent to vendor/package-name.
The composer_package_name name must be available on Packagist.
Set up a Packagist account and package
- Log in or sign up at Packagist.
- Navigate into your profile by clicking on your username in the top right corner.
- Navigate to the “Settings” section of your profile, and ensure your account is connected via GitHub.
- Click the “Submit” button at the top and add your production GitHub repository, and follow the packagist instructions.
Find your Packagist “Safe API Token”
- Ensuring you are signed in on Packagist, click on your username in the top right corner.
- Ensure the sidebar is set to the “Profile” section.
- Click the “Show Safe API Token” button, it is not necessary to use the “Main API Token”.
Add secrets to your production repo
- Ensure the Stainless GitHub app is installed in your production repo or your GitHub actions environment has your Stainless API Key.
- In the production repo, navigate to Secrets and variables > Actions > New repository secret.
The URL should look like
https://github.com/<org>/<repo>/settings/secrets/actions/new. - Add the following secrets:
-
PACKAGIST_SAFE_KEY: Your Packagist Safe API Token -
PACKAGIST_USERNAME: Your username in Packagist as it appears in the top-right corner.