Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex API Gateway
  • Getting started
    • All tutorials
    • Deploying a web application using the Java Servlet API
    • Creating a skill for Alice and a website with authorization
    • Developing a Slack bot
    • Developing a Telegram bot
    • Developing a Telegram bot for text and audio recognition
    • Developing a custom integration
    • Developing CRUD APIs for movie services
    • Working with an API gateway via WebSocket
    • Creating an interactive serverless application using WebSocket
    • Building a CI/CD pipeline in GitLab with serverless products
    • Interactive debugging of Cloud Functions functions
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Canary release of a Cloud Functions function
    • Using API Gateway to set up speech synthesis in Yandex SpeechKit
    • Running a containerized app in Yandex Serverless Containers
    • URL shortener
    • Entering data into storage systems
    • API Gateway protection with Smart Web Security
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Required paid resources
  • Create a service account
  • Create an API gateway
  • Check the result
  • How to delete the resources you created
  1. Tutorials
  2. Using API Gateway to set up speech synthesis in Yandex SpeechKit

Using Yandex API Gateway to set up speech synthesis in Yandex SpeechKit

Written by
Yandex Cloud
Updated at June 9, 2025
  • Getting started
    • Required paid resources
  • Create a service account
  • Create an API gateway
  • Check the result
  • How to delete the resources you created

With serverless technology, you can create your own integration with Yandex Cloud services.

In this tutorial, you will create a custom setup with an OpenAPI 3.0-based API gateway with HTTP integration.

The users' speech synthesis requests run through the API gateway that uses HTTP integration to call the SpeechKit API and retrieve the synthesized speech from SpeechKit.

To set up SpeechKit speech synthesis using Yandex API Gateway:

  1. Get your cloud ready.
  2. Create a service account.
  3. Create an API gateway.
  4. Check the result.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The new infrastructure support cost includes:

  • Fee for the number of requests to the API gateway and outbound traffic (see Yandex API Gateway pricing).
  • Fee for using SpeechKit (see SpeechKit pricing).

Create a service accountCreate a service account

Create a service account named speechkit-sa with the ai.speechkit-tts.user role for the folder where you are creating your infrastructure:

Management console
CLI
API
  1. In the management console, select the folder where you want to create a service account.
  2. In the list of services, select Identity and Access Management.
  3. Click Create service account.
  4. Enter the service account name: speechkit-sa.
  5. Click Add role and select ai.speechkit-tts.user.
  6. Click Create.

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

  1. Create a service account named speechkit-sa:

    yc iam service-account create speechkit-sa
    

    Result:

    id: nfersamh4sjq********
    folder_id: b1gc1t4cb638********
    created_at: "2023-09-21T10:36:29.726397755Z"
    name: speechkit-sa
    

    Save the ID of the speechkit-sa service account (id) and the ID of the folder where you created it (folder_id).

    For more information about the yc iam service-account create command, see the CLI reference.

  2. Assign the ai.speechkit-tts.user role for the folder to the service account by specifying the folder and service account IDs you previously saved:

    yc resource-manager folder add-access-binding <folder_ID> \
      --role ai.speechkit-tts.user \
      --subject serviceAccount:<service_account_ID>
    

    For more information about the yc resource-manager folder add-access-binding command, see the CLI reference.

To create a service account, use the create method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call.

To assign the ai.speechkit-tts.user role for a folder to a service account, use the setAccessBindings method for the ServiceAccount resource or the ServiceAccountService/SetAccessBindings gRPC API call.

Create an API gatewayCreate an API gateway

Management console
CLI
API
  1. In the management console, select the folder where you want to create an API gateway.

  2. In the list of services, select API Gateway.

  3. Click Create API gateway.

  4. In the Name field, enter speechkit-api-gw.

  5. Under Specification, add the following specification and provide the speechkit-sa service account ID in the service_account_id parameter:

    openapi: 3.0.0
    info:
      title: Sample API
      version: 1.0.0
    
    paths:
      /synthesis:
        post:
          requestBody:
            description: "/synthesis"
            content:
              application/json:
                schema:
                  type: object
                  x-yc-schema-mapping:
                    type: static
                    template:
                      text: "${.text}"
                      hints:
                        - voice: "lera"
                        - role: "friendly"
                        - audioTemplate:
                            audio:
                              audioSpec:
                                containerAudio:
                                  containerAudioType: "MP3"
          responses:
            200:
              description: "/synthesis"
              content:
                application/json:
                  schema:
                    type: object
                    x-yc-schema-mapping:
                      type: static
                      template:
                        data: "${.result.audioChunk.data}"
          x-yc-apigateway-integration:
            http_method: post
            type: http
            url: https://tts.api.cloud.yandex.net/tts/v3/utteranceSynthesis
            service_account_id: "<service_account_ID>"
    
  6. Click Create.

  7. Wait until the status of the API gateway you just created switches to running, and then click the row with the gateway name.

  8. In the window that opens, copy the Default domain field value. You will need it later to test the API gateway.

  1. Save the following specification to speechkit-gw.yaml and provide the speechkit-sa service account ID in the service_account_id parameter:

    openapi: 3.0.0
    info:
      title: Sample API
      version: 1.0.0
    
    paths:
      /synthesis:
        post:
          requestBody:
            description: "/synthesis"
            content:
              application/json:
                schema:
                  type: object
                  x-yc-schema-mapping:
                    type: static
                    template:
                      text: "${.text}"
                      hints:
                        - voice: "lera"
                        - role: "friendly"
                        - audioTemplate:
                            audio:
                              audioSpec:
                                containerAudio:
                                  containerAudioType: "MP3"
          responses:
            200:
              description: "/synthesis"
              content:
                application/json:
                  schema:
                    type: object
                    x-yc-schema-mapping:
                      type: static
                      template:
                        data: "${.result.audioChunk.data}"
          x-yc-apigateway-integration:
            http_method: post
            type: http
            url: https://tts.api.cloud.yandex.net/tts/v3/utteranceSynthesis
            service_account_id: "<service_account_ID>"
    
  2. Run this command:

    yc serverless api-gateway create \
      --name speechkit-api-gw \
      --spec=speechkit-gw.yaml
    

    Where:

    • --name: API gateway name.
    • --spec: Path to the specification file.

    Result:

    done (2s)
    id: d5ddbmungf72********
    folder_id: b1gt6g8ht345********
    created_at: "2024-08-19T18:58:32.101Z"
    name: speechkit-api-gw
    status: ACTIVE
    domain: d5dm1lba80md********.i9******.apigw.yandexcloud.net
    connectivity: {}
    log_options:
      folder_id: b1gt6g8ht345********
    execution_timeout: 300s
    

Save the service domain (the domain field value) of the API gateway you created. You will need it later to test the API gateway.

For more information about the yc serverless api-gateway create command, see the CLI reference.

To create an API gateway, use the create REST API method for the ApiGateway resource or the ApiGatewayService/Create gRPC API call.

Check the resultCheck the result

Note

You will need cURL and jq to test your API gateway.

Send a request to your API gateway, providing the service domain value you previously saved:

curl --verbose \
  https://<service_domain>/synthesis \
  --data '{"text": "Hi! S+erverless Api G+ateway now has a new feature: converting HTTP request or response body!"}' \
  | jq -r  '.data' | while read chunk; do base64 -d <<< "$chunk" >> audio.mp3; done

After you run the above command, the system will save the synthesized speech to the audio.mp3 file in the current directory. You can listen to the output file in your browser, e.g., Yandex Browser or Mozilla Firefox.

To learn more about the format of the text provided in the -d parameter, see this Yandex SpeechKit article.

How to delete the resources you createdHow to delete the resources you created

If you no longer need the resources you created:

  • Delete the API gateway.
  • Delete the service account.

Was the article helpful?

Previous
Canary release of a Cloud Functions function
Next
Running a containerized app in Yandex Serverless Containers
© 2025 Direct Cursus Technology L.L.C.