SDKs
Simple security schemes
Basic HTTP authentication
Section titled “Basic HTTP authentication”Basic HTTP authentication is supported in all languages.
Define type: http and scheme: basic to generate authentication that prompts users for a username and password when instantiating the SDK. The SDK will encode the username and password into a Base64 string and pass it in the Authorization header.
paths: /drinks: get: operationId: listDrinks summary: Get a list of drinks. description: Get a list of drinks, if authenticated this will include stock levels and product codes otherwise it will only include public information. tags: - drinkscomponents: securitySchemes: auth: type: http scheme: basicsecurity: - auth: []import { SDK } from "speakeasy"; async function run() { const sdk = new SDK({ security: { username: "<YOUR_USERNAME_HERE>", password: "<YOUR_PASSWORD_HERE>", }, }); const result = await sdk.drinks.listDrinks(); // Handle the result console.log(result);} run();import speakeasyfrom speakeasy.models import components s = speakeasy.SDK( security=components.Security( username="<YOUR_USERNAME_HERE>", password="<YOUR_PASSWORD_HERE>", ),) res = s.drinks.list_drinks() if res.drinks is not None: # handle response passpackage main import ( "context" "log" "speakeasy" "speakeasy/models/components") func main() { s := speakeasy.New( speakeasy.WithSecurity(components.Security{ Username: "<YOUR_USERNAME_HERE>", Password: "<YOUR_PASSWORD_HERE>", }), ) ctx := context.Background() res, err := s.Drinks.ListDrinks(ctx) if err != nil { log.Fatal(err) } if res.Drinks != nil { // handle response }}package hello.world; import dev.speakeasyapi.speakeasy.SDK;import dev.speakeasyapi.speakeasy.models.components.*;import dev.speakeasyapi.speakeasy.models.components.Security;import dev.speakeasyapi.speakeasy.models.operations.*;import dev.speakeasyapi.speakeasy.models.operations.ListDrinksResponse;import java.math.BigDecimal;import java.math.BigInteger;import java.time.LocalDate;import java.time.OffsetDateTime;import java.util.Optional;import static java.util.Map.entry; public class Application { public static void main(String[] args) { try { SDK sdk = SDK.builder() .security(Security.builder() .username("<YOUR_USERNAME_HERE>") .password("<YOUR_PASSWORD_HERE>") .build()) .build(); ListDrinksResponse res = sdk.drinks().listDrinks() .call(); if (res.drinks().isPresent()) { // handle response } } catch (dev.speakeasyapi.speakeasy.models.errors.SDKError e) { // handle exception } catch (Exception e) { // handle exception } }}using Speakeasy;using Speakeasy.Models.Components; var sdk = new SDK( security: new Security() { Username = "<YOUR_USERNAME_HERE>", Password = "<YOUR_PASSWORD_HERE>", }); try{ var res = await sdk.Drinks.ListDrinksAsync(); if (res.Drinks != null) { // handle response }}catch (Exception ex){ // handle exception}use OpenAPI\OpenAPI;use OpenAPI\OpenAPI\Models\Shared; $sdk = OpenAPI\SDK::builder()->setSecurity( new Shared\Security( password: 'YOUR_PASSWORD', username: 'YOUR_USERNAME', );)->build(); try { $res = $sdk->drinks->listDrinks(); if ($res->Drinks != null) { // handle response }} catch (Errors\ErrorThrowable $e) { // handle exception}require 'openapi' Models = ::OpenApiSDK::Models s = ::OpenApiSDK::SDK.new( security: Models::Shared::Security.new( username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', ), ) begin res = s.drinks.list_drinks unless res.drinks.nil? # handle response end rescue Models::Errors::APIError => e # handle exception raise e end API key authentication
Section titled “API key authentication”API key authentication is supported in all languages.
Define type: apiKey and in: [header,query] to generate authentication that prompts users for a key when instantiating the SDK. The SDK passes the key in a header or query parameter, depending on the in property, and uses the name field as the header or key name.
paths: /drinks: get: operationId: listDrinks summary: Get a list of drinks. description: Get a list of drinks, if authenticated this will include stock levels and product codes otherwise it will only include public information. tags: - drinks responses: "200": description: OK #...components: securitySchemes: api_key: type: apiKey name: api_key in: headersecurity: - api_key: []import { SDK } from "speakeasy"; async function run() { const sdk = new SDK({ apiKey: "<YOUR_API_KEY_HERE>", }); const result = await sdk.drinks.listDrinks(); // Handle the result console.log(result);} run();import speakeasy s = speakeasy.SDK( api_key="<YOUR_API_KEY_HERE>",) res = s.drinks.list_drinks() if res.drinks is not None: # handle response passpackage main import ( "context" "log" "speakeasy" "speakeasy/models/components") func main() { s := speakeasy.New( speakeasy.WithSecurity("<YOUR_API_KEY_HERE>"), ) ctx := context.Background() res, err := s.Drinks.ListDrinks(ctx) if err != nil { log.Fatal(err) } if res.Drinks != nil { // handle response }}package hello.world; import dev.speakeasyapi.speakeasy.SDK;import dev.speakeasyapi.speakeasy.models.components.*;import dev.speakeasyapi.speakeasy.models.components.Security;import dev.speakeasyapi.speakeasy.models.operations.*;import dev.speakeasyapi.speakeasy.models.operations.ListDrinksResponse;import java.math.BigDecimal;import java.math.BigInteger;import java.time.LocalDate;import java.time.OffsetDateTime;import java.util.Optional;import static java.util.Map.entry; public class Application { public static void main(String[] args) { try { SDK sdk = SDK.builder() .apiKey("<YOUR_API_KEY_HERE>") .build(); ListDrinksResponse res = sdk.drinks().listDrinks() .call(); if (res.drinks().isPresent()) { // handle response } } catch (dev.speakeasyapi.speakeasy.models.errors.SDKError e) { // handle exception } catch (Exception e) { // handle exception } }}using Speakeasy;using Speakeasy.Models.Components; var sdk = new SDK( security: new Security() { ApiKey = "<YOUR_API_KEY_HERE>" }); try{ var res = await sdk.Drinks.ListDrinksAsync(); if (res.Drinks != null) { // handle response }}catch (Exception ex){ // handle exception}use OpenAPI\OpenAPI;use OpenAPI\OpenAPI\Models\Shared; $sdk = OpenAPI\SDK::builder()->setSecurity( new Shared\Security( apiKey: "<YOUR_API_KEY_HERE>" );)->build(); try { $res = $sdk->drinks->listDrinks(); if ($res->Drinks != null) { // handle response }} catch (Errors\ErrorThrowable $e) { // handle exception}require 'openapi' Models = ::OpenApiSDK::Models s = ::OpenApiSDK::SDK.new( security: Models::Shared::Security.new( api_key: '<YOUR_API_KEY_HERE>', ),) begin res = s.drinks.list_drinks unless res.drinks.nil? # handle response endrescue Models::Errors::APIError => e # handle exception raise eendBearer token authentication
Section titled “Bearer token authentication”Bearer token authentication is supported in all languages.
Define type: http and scheme: bearer to generate authentication that prompts users for a token when instantiating the SDK.
The SDK will pass the token in the Authorization header using the Bearer scheme, appending the Bearer prefix to the token if not already present.
paths: /drinks: get: operationId: listDrinks summary: Get a list of drinks. description: Get a list of drinks, if authenticated this will include stock levels and product codes otherwise it will only include public information. tags: - drinkscomponents: securitySchemes: auth: type: http scheme: bearersecurity: - auth: []import { SDK } from "speakeasy"; async function run() { const sdk = new SDK({ auth: "<YOUR_BEARER_TOKEN_HERE>", }); const result = await sdk.drinks.listDrinks(); // Handle the result console.log(result);} run();import speakeasy s = speakeasy.SDK( auth="<YOUR_BEARER_TOKEN_HERE>",) res = s.drinks.list_drinks() if res.drinks is not None: # handle response passpackage main import ( "context" "log" "speakeasy" "speakeasy/models/components") func main() { s := speakeasy.New( speakeasy.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"), ) ctx := context.Background() res, err := s.Drinks.ListDrinks(ctx) if err != nil { log.Fatal(err) } if res.Drinks != nil { // handle response }}package hello.world; import dev.speakeasyapi.speakeasy.SDK;import dev.speakeasyapi.speakeasy.models.components.*;import dev.speakeasyapi.speakeasy.models.components.Security;import dev.speakeasyapi.speakeasy.models.operations.*;import dev.speakeasyapi.speakeasy.models.operations.ListDrinksResponse;import java.math.BigDecimal;import java.math.BigInteger;import java.time.LocalDate;import java.time.OffsetDateTime;import java.util.Optional;import static java.util.Map.entry; public class Application { public static void main(String[] args) { try { SDK sdk = SDK.builder() .auth("<YOUR_BEARER_TOKEN_HERE>") .build(); ListDrinksResponse res = sdk.drinks().listDrinks() .call(); if (res.drinks().isPresent()) { // handle response } } catch (dev.speakeasyapi.speakeasy.models.errors.SDKError e) { // handle exception } catch (Exception e) { // handle exception } }}using Speakeasy;using Speakeasy.Models.Components; var sdk = new SDK( security: new Security() { Auth = "<YOUR_BEARER_TOKEN_HERE>" }); try{ var res = await sdk.Drinks.ListDrinksAsync(); if (res.Drinks != null) { // handle response }}catch (Exception ex){ // handle exception}use OpenAPI\OpenAPI;use OpenAPI\OpenAPI\Models\Components; $sdk = OpenAPI\SDK::builder()->setSecurity( new Components\Security( auth: "<YOUR_BEARER_TOKEN_HERE>" );)->build(); try { $res = $sdk->drinks->listDrinks(); if ($res->Drinks != null) { // handle response }} catch (Errors\ErrorThrowable $e) { // handle exception}require 'openapi' Models = ::OpenApiSDK::Models s = ::OpenApiSDK::SDK.new( security: Models::Shared::Security.new( auth: '<YOUR_BEARER_TOKEN_HERE>', ), ) begin res = s.drinks.list_drinks unless res.drinks.nil? # handle response end rescue Models::Errors::APIError => e # handle exception raise e end