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;
$security = new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
);
$sdk = SpeakeasyClientSDK\SDK::builder()->setSecurity($security)->build();
$request = new Shared\CodeSampleSchemaInput(
languages: [
'<value>',
],
schemaFile: new Shared\SchemaFile(
content: '0xc3dD8BfBef',
fileName: 'example.file',
),
);
$response = $sdk->generateCodeSamplePreview(
request: $request
);
if ($response->twoHundredApplicationJsonBytes !== null) {
// handle response
}
Available methods
- createRemoteSource - Configure a new remote source
- getBlob - Get blob for a particular digest
- getManifest - Get manifest for a particular reference
- getNamespaces - Each namespace contains many revisions.
- getRevisions
- getTags
- listRemoteSources - Get remote sources attached to a particular namespace
- postTags - Add tags to an existing revision
- preflight - Get access token for communicating with OCI distribution endpoints
- setVisibility - Set visibility of a namespace with an existing metadata entry
- getAccessToken - Get or refresh an access token for the current workspace.
- getUser - Get information about the current user.
- getAccess - Get access allowances for a particular workspace
- validateApiKey - Validate the current api key.
- getEventsByTarget - Load recent events for a particular workspace
- getTargets - Load targets for a particular workspace
- getTargetsDeprecated - Load targets for a particular workspace
- post - Post events for a specific workspace
- search - Search events for a particular workspace by any field
- checkAccess
- getAction
- getSetup
- checkPublishingPRs
- checkPublishingSecrets
- configureCodeSamples
- configureMintlifyRepo
- configureTarget
- storePublishingSecrets
- triggerAction
- linkGithub
- createFreeTrial - Create a free trial for an organization
- create - Create an organization
- get - Get organization
- getUsage - Get billing usage summary for a particular organization
- getAll - Get organizations for a user
- getChangesReportSignedUrl - Get the signed access url for the change reports for a particular document.
- getLintingReportSignedUrl - Get the signed access url for the linting reports for a particular document.
- uploadReport - Upload a report.
- generateCodeSamplePreview - Generate Code Sample previews from a file and configuration parameters.
- generateCodeSamplePreviewAsync - Initiate asynchronous Code Sample preview generation from a file and configuration parameters, receiving an async JobID response for polling.
- getCodeSamplePreviewAsync - Poll for the result of an asynchronous Code Sample preview generation.
- create - Shorten a URL.
- activateSubscriptionNamespace - Activate an ignored namespace for a subscription
- ignoreSubscriptionNamespace - Ignored a namespace for a subscription
- suggest - Generate suggestions for improving an OpenAPI document.
- suggestItems - Generate generic suggestions for a list of items.
- suggestOpenAPI - (DEPRECATED) Generate suggestions for improving an OpenAPI document.
- suggestOpenAPIRegistry - Generate suggestions for improving an OpenAPI document stored in the registry.
- create - Create a workspace
- createToken - Create a token for a particular workspace
- deleteToken - Delete a token for a particular workspace
- getByID - Get workspace
- get - Get workspace by context
- getFeatureFlags - Get workspace feature flags
- getSettings - Get workspace settings
- getTeam - Get team members for a particular workspace
- getTokens - Get tokens for a particular workspace
- getAll - Get workspaces for a user
- grantAccess - Grant a user access to a particular workspace
- revokeAccess - Revoke a user's access to a particular workspace
- update - Update workspace details
- updateSettings - Update workspace settings
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
}
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 generateCodeSamplePreview
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
Errorors\Error | 4XX, 5XX | application/json |
declare(strict_types=1);
require 'vendor/autoload.php';
use Speakeasy\SpeakeasyClientSDK;
use Speakeasy\SpeakeasyClientSDK\Models\Shared;
$security = new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
);
$sdk = SpeakeasyClientSDK\SDK::builder()->setSecurity($security)->build();
try {
$request = new Shared\CodeSampleSchemaInput(
languages: [
'<value>',
],
schemaFile: new Shared\SchemaFile(
content: '0xc3dD8BfBef',
fileName: 'example.file',
),
);
$response = $sdk->generateCodeSamplePreview(
request: $request
);
if ($response->twoHundredApplicationJsonBytes !== null) {
// 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;
$security = new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
);
$sdk = SpeakeasyClientSDK\SDK::builder()
->setServer("prod")
->setSecurity($security)->build();
$request = new Shared\CodeSampleSchemaInput(
languages: [
'<value>',
],
schemaFile: new Shared\SchemaFile(
content: '0xc3dD8BfBef',
fileName: 'example.file',
),
);
$response = $sdk->generateCodeSamplePreview(
request: $request
);
if ($response->twoHundredApplicationJsonBytes !== null) {
// 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;
$security = new Shared\Security(
apiKey: '<YOUR_API_KEY_HERE>',
);
$sdk = SpeakeasyClientSDK\SDK::builder()
->setServerURL('https://api.prod.speakeasyapi.dev')
->setSecurity($security)->build();
$request = new Shared\CodeSampleSchemaInput(
languages: [
'<value>',
],
schemaFile: new Shared\SchemaFile(
content: '0xc3dD8BfBef',
fileName: 'example.file',
),
);
$response = $sdk->generateCodeSamplePreview(
request: $request
);
if ($response->twoHundredApplicationJsonBytes !== null) {
// 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 !