Skip to content
FeedbackDashboard
Codegen targets

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:

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-08
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: true

For a complete list of configuration options, see the PHP target reference.

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)

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: true

The 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
  1. Log in or sign up at Packagist.
  2. Navigate into your profile by clicking on your username in the top right corner.
  3. Navigate to the “Settings” section of your profile, and ensure your account is connected via GitHub.
  4. Click the “Submit” button at the top and add your production GitHub repository, and follow the packagist instructions.
Find your Packagist “Safe API Token”
  1. Ensuring you are signed in on Packagist, click on your username in the top right corner.
  2. Ensure the sidebar is set to the “Profile” section.
  3. Click the “Show Safe API Token” button, it is not necessary to use the “Main API Token”.
Add secrets to your production repo
  1. Ensure the Stainless GitHub app is installed in your production repo or your GitHub actions environment has your Stainless API Key.
  2. 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.
  3. 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.