Speakeasy API: The Speakeasy API allows teams to manage common operations with their APIs
For more information about the API: The Speakeasy Platform Documentation
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
implementation 'dev.speakeasyapi:javaclientsdk:7.25.0'
Maven:
<dependency>
<groupId>dev.speakeasyapi</groupId>
<artifactId>javaclientsdk</artifactId>
<version>7.25.0</version>
</dependency>
After cloning the git repository to your file system you can build the SDK artifact from source to the build
directory by running ./gradlew build
on *nix systems or gradlew.bat
on Windows systems.
If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):
On *nix:
./gradlew publishToMavenLocal -Pskip.signing
On Windows:
gradlew.bat publishToMavenLocal -Pskip.signing
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetApisRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetApisResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
GetApisRequest req = GetApisRequest.builder()
.build();
GetApisResponse res = sdk.apis().getApis()
.request(req)
.call();
if (res.apis().isPresent()) {
// handle response
}
}
}
Available methods
- deleteApiEndpoint - Delete an ApiEndpoint.
- findApiEndpoint - Find an ApiEndpoint via its displayName.
- generateOpenApiSpecForApiEndpoint - Generate an OpenAPI specification for a particular ApiEndpoint.
- generatePostmanCollectionForApiEndpoint - Generate a Postman collection for a particular ApiEndpoint.
- getAllApiEndpoints - Get all Api endpoints for a particular apiID.
- getAllForVersionApiEndpoints - Get all ApiEndpoints for a particular apiID and versionID.
- getApiEndpoint - Get an ApiEndpoint.
- upsertApiEndpoint - Upsert an ApiEndpoint.
- deleteApi - Delete an Api.
- generateOpenApiSpec - Generate an OpenAPI specification for a particular Api.
- generatePostmanCollection - Generate a Postman collection for a particular Api.
- getAllApiVersions - Get all Api versions for a particular ApiEndpoint.
- getApis - Get a list of Apis for a given workspace
- upsertApi - Upsert an Api
- validateApiKey - Validate the current api key.
- getEmbedAccessToken - Get an embed access token for the current workspace.
- getValidEmbedAccessTokens - Get all valid embed access tokens for the current workspace.
- revokeEmbedAccessToken - Revoke an embed access EmbedToken.
- postWorkspaceEvents - Post events for a specific workspace
- deleteVersionMetadata - Delete metadata for a particular apiID and versionID.
- getVersionMetadata - Get all metadata for a particular apiID and versionID.
- insertVersionMetadata - Insert metadata for a particular apiID and versionID.
- generateRequestPostmanCollection - Generate a Postman collection for a particular request.
- getRequestFromEventLog - Get information about a particular request.
- queryEventLog - Query the event log to retrieve a list of requests.
- deleteSchema - Delete a particular schema revision for an Api.
- downloadSchema - Download the latest schema for a particular apiID.
- downloadSchemaRevision - Download a particular schema revision for an Api.
- getSchema - Get information about the latest schema.
- getSchemaDiff - Get a diff of two schema revisions for an Api.
- getSchemaRevision - Get information about a particular schema revision for an Api.
- getSchemas - Get information about all schemas associated with a particular apiID.
- registerSchema - Register a schema.
You can override the default server globally using the .server(AvailableServers server)
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 |
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.operations.DeleteApiRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.DeleteApiResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
RyanTest sdk = RyanTest.builder()
.serverIndex(0)
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
DeleteApiRequest req = DeleteApiRequest.builder()
.apiID("<id>")
.versionID("<id>")
.build();
DeleteApiResponse res = sdk.apis().deleteApi()
.request(req)
.call();
// handle response
}
}
The default server can also be overridden globally using the .serverURL(String serverUrl)
builder method when initializing the SDK client instance. For example:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.operations.DeleteApiRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.DeleteApiResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
RyanTest sdk = RyanTest.builder()
.serverURL("https://api.prod.speakeasyapi.dev")
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
DeleteApiRequest req = DeleteApiRequest.builder()
.apiID("<id>")
.versionID("<id>")
.build();
DeleteApiResponse res = sdk.apis().deleteApi()
.request(req)
.call();
// handle response
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will throw a models/errors/SDKError
exception. 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 postWorkspaceEvents
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
models/errors/Error | 5XX | application/json |
models/errors/SDKError | 4XX | */* |
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CliEvent;
import dev.speakeasyapi.javaclientsdk.models.shared.InteractionType;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
PostWorkspaceEventsRequest req = PostWorkspaceEventsRequest.builder()
.requestBody(List.of(
CliEvent.builder()
.createdAt(OffsetDateTime.parse("2025-03-02T10:07:28.113Z"))
.executionId("<id>")
.id("<id>")
.interactionType(InteractionType.TARGET_GENERATE)
.localStartedAt(OffsetDateTime.parse("2025-08-12T17:54:17.538Z"))
.speakeasyApiKeyName("<value>")
.speakeasyVersion("<value>")
.success(true)
.workspaceId("<id>")
.build()))
.workspaceID("<id>")
.build();
PostWorkspaceEventsResponse res = sdk.events().postWorkspaceEvents()
.request(req)
.call();
// handle response
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
apiKey |
apiKey | API key |
You can set the security parameters through the security
builder method when initializing the SDK client instance. For example:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.operations.DeleteApiRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.DeleteApiResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
DeleteApiRequest req = DeleteApiRequest.builder()
.apiID("<id>")
.versionID("<id>")
.build();
DeleteApiResponse res = sdk.apis().deleteApi()
.request(req)
.call();
// 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 workspaceID
to "<id>"
at SDK initialization and then you do not have to pass the same value on calls to operations like postWorkspaceEvents
. 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 | java.lang.String | The workspaceID parameter. |
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CliEvent;
import dev.speakeasyapi.javaclientsdk.models.shared.InteractionType;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
PostWorkspaceEventsRequest req = PostWorkspaceEventsRequest.builder()
.requestBody(List.of(
CliEvent.builder()
.createdAt(OffsetDateTime.parse("2025-03-02T10:07:28.113Z"))
.executionId("<id>")
.id("<id>")
.interactionType(InteractionType.TARGET_GENERATE)
.localStartedAt(OffsetDateTime.parse("2025-08-12T17:54:17.538Z"))
.speakeasyApiKeyName("<value>")
.speakeasyVersion("<value>")
.success(true)
.workspaceId("<id>")
.build()))
.workspaceID("<id>")
.build();
PostWorkspaceEventsResponse res = sdk.events().postWorkspaceEvents()
.request(req)
.call();
// 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, you can provide a RetryConfig
object through the retryConfig
builder method:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CliEvent;
import dev.speakeasyapi.javaclientsdk.models.shared.InteractionType;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import dev.speakeasyapi.javaclientsdk.utils.BackoffStrategy;
import dev.speakeasyapi.javaclientsdk.utils.RetryConfig;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
PostWorkspaceEventsRequest req = PostWorkspaceEventsRequest.builder()
.requestBody(List.of(
CliEvent.builder()
.createdAt(OffsetDateTime.parse("2025-03-02T10:07:28.113Z"))
.executionId("<id>")
.id("<id>")
.interactionType(InteractionType.TARGET_GENERATE)
.localStartedAt(OffsetDateTime.parse("2025-08-12T17:54:17.538Z"))
.speakeasyApiKeyName("<value>")
.speakeasyVersion("<value>")
.success(true)
.workspaceId("<id>")
.build()))
.workspaceID("<id>")
.build();
PostWorkspaceEventsResponse res = sdk.events().postWorkspaceEvents()
.request(req)
.retryConfig(RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(1L, TimeUnit.MILLISECONDS)
.maxInterval(50L, TimeUnit.MILLISECONDS)
.maxElapsedTime(1000L, TimeUnit.MILLISECONDS)
.baseFactor(1.1)
.jitterFactor(0.15)
.retryConnectError(false)
.build())
.build())
.call();
// handle response
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can provide a configuration at SDK initialization:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.PostWorkspaceEventsResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CliEvent;
import dev.speakeasyapi.javaclientsdk.models.shared.InteractionType;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import dev.speakeasyapi.javaclientsdk.utils.BackoffStrategy;
import dev.speakeasyapi.javaclientsdk.utils.RetryConfig;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.retryConfig(RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(1L, TimeUnit.MILLISECONDS)
.maxInterval(50L, TimeUnit.MILLISECONDS)
.maxElapsedTime(1000L, TimeUnit.MILLISECONDS)
.baseFactor(1.1)
.jitterFactor(0.15)
.retryConnectError(false)
.build())
.build())
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
PostWorkspaceEventsRequest req = PostWorkspaceEventsRequest.builder()
.requestBody(List.of(
CliEvent.builder()
.createdAt(OffsetDateTime.parse("2025-03-02T10:07:28.113Z"))
.executionId("<id>")
.id("<id>")
.interactionType(InteractionType.TARGET_GENERATE)
.localStartedAt(OffsetDateTime.parse("2025-08-12T17:54:17.538Z"))
.speakeasyApiKeyName("<value>")
.speakeasyVersion("<value>")
.success(true)
.workspaceId("<id>")
.build()))
.workspaceID("<id>")
.build();
PostWorkspaceEventsResponse res = sdk.events().postWorkspaceEvents()
.request(req)
.call();
// handle response
}
}