The SDK relies on Composer to manage its dependencies.
To install the SDK and add it as a dependency to an existing composer.json
file:
composer require "speakeasy-api/speakeasy-client-sdk-php"
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
$request = new Shared\RemoteSource(
inputs: [
new Shared\RemoteDocument(
registryUrl: 'https://productive-swine.net',
),
],
output: new Shared\RemoteDocument(
registryUrl: 'https://spiteful-apricot.info',
),
);
$response = $sdk->artifacts->createRemoteSource(
request: $request
);
if ($response->statusCode === 200) {
// handle response
}
This SDK supports the following security schemes globally:
Name | Type | Scheme |
---|---|---|
apiKey |
apiKey | API key |
bearer |
http | HTTP Bearer |
workspaceIdentifier |
apiKey | API key |
You can set the security parameters through the setSecurity
function on the SDKBuilder
when initializing the SDK. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
$request = new Shared\RemoteSource(
inputs: [
new Shared\RemoteDocument(
registryUrl: 'https://productive-swine.net',
),
],
output: new Shared\RemoteDocument(
registryUrl: 'https://spiteful-apricot.info',
),
);
$response = $sdk->artifacts->createRemoteSource(
request: $request
);
if ($response->statusCode === 200) {
// handle response
}
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set workspace_id
to '<id>'
at SDK initialization and then you do not have to pass the same value on calls to operations like getAccessToken
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available.
Name | Type | Description |
---|---|---|
workspaceId | string | The workspaceId parameter. |
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Operations;
$sdk = SpeakeasyClientSDK\SDK::builder()->build();
$request = new Operations\GetAccessTokenRequest(
workspaceId: '<id>',
);
$response = $sdk->auth->getAccessToken(
request: $request
);
if ($response->accessToken !== null) {
// handle response
}
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide an Options
object built with a RetryConfig
object to the call:
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Operations;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
use Speakeasy\SpeakeasyClientSDK\Utils\Retry;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
$request = new Operations\GetWorkspaceAccessRequest();
$response = $sdk->auth->getAccess(
request: $request,
options: Utils\Options->builder()->setRetryConfig(
new Retry\RetryConfigBackoff(
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
retryConnectionErrors: false,
))->build()
);
if ($response->accessDetails !== null) {
// handle response
}
If you’d like to override the default retry strategy for all operations that support retries, you can pass a RetryConfig
object to the SDKBuilder->setRetryConfig
function when initializing the SDK:
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Operations;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
use Speakeasy\SpeakeasyClientSDK\Utils\Retry;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setRetryConfig(
new Retry\RetryConfigBackoff(
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
retryConnectionErrors: false,
)
)
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
$request = new Operations\GetWorkspaceAccessRequest();
$response = $sdk->auth->getAccess(
request: $request
);
if ($response->accessDetails !== null) {
// handle response
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default an API error will raise a Errorors\SDKException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
$message |
string | The error message |
$statusCode |
int | The HTTP status code |
$rawResponse |
?\Psr\Http\Message\ResponseInterface | The raw HTTP response |
$body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the createRemoteSource
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errorors\Error | 4XX | application/json |
Errorors\SDKException | 5XX | */* |
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
try {
$request = new Shared\RemoteSource(
inputs: [
new Shared\RemoteDocument(
registryUrl: 'https://productive-swine.net',
),
],
output: new Shared\RemoteDocument(
registryUrl: 'https://spiteful-apricot.info',
),
);
$response = $sdk->artifacts->createRemoteSource(
request: $request
);
if ($response->statusCode === 200) {
// handle response
}
} catch (Errorors\ErrorThrowable $e) {
// handle $e->$container data
throw $e;
} catch (Errorors\SDKException $e) {
// handle default exception
throw $e;
}
You can override the default server globally using the setServer(string $serverName)
builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
Name | Server |
---|---|
prod |
https://api.prod.speakeasyapi.dev |
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setServer("prod")
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
$request = new Shared\RemoteSource(
inputs: [
new Shared\RemoteDocument(
registryUrl: 'https://productive-swine.net',
),
],
output: new Shared\RemoteDocument(
registryUrl: 'https://spiteful-apricot.info',
),
);
$response = $sdk->artifacts->createRemoteSource(
request: $request
);
if ($response->statusCode === 200) {
// handle response
}
The default server can also be overridden globally using the setServerUrl(string $serverUrl)
builder method when initializing the SDK client instance. For example:
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
$sdk = SpeakeasyClientSDK\SDK::builder()
->setServerURL('https://api.prod.speakeasyapi.dev')
->setSecurity(
new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
)
)
->build();
$request = new Shared\RemoteSource(
inputs: [
new Shared\RemoteDocument(
registryUrl: 'https://productive-swine.net',
),
],
output: new Shared\RemoteDocument(
registryUrl: 'https://spiteful-apricot.info',
),
);
$response = $sdk->artifacts->createRemoteSource(
request: $request
);
if ($response->statusCode === 200) {
// handle response
}
Speakeasy API: The Subscriptions API manages subscriptions for CLI and registry events
For more information about the API: The Speakeasy Platform Documentation
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we’ll do our best to include it in a future release !