Cognitive Services SDK Samples

These samples will show you how to get up and running using the SDKs for various Cognitive Services. They'll cover a few rudimentary use cases and hopefully express best practices for interacting with the data from these APIs.


This project framework provides examples for the following services:

Run this sample

  1. If you don't already have it, get ruby.

  2. Clone the repository.

    git clone
  3. Install the dependencies.

    cd cognitive-services-ruby-sdk-samples
    bundle install
  4. Get a cognitive services API key with which to authenticate the SDK's calls. Sign up here by navigating to the right service and acquiring an API key. You can get a trial key for free which will expire after 30 days.

  5. Set the following environment variables. You only need to set the environment variables for which you want to run the samples.

No. Service Name Environment Variable to set Notes
1 azure_cognitiveservices_computervision COMPUTERVISION_SUBSCRIPTION_KEY Your Service Key
2 azure_cognitiveservices_customsearch CUSTOMSEARCH_SUBSCRIPTION_KEY Your Service Key
CUSTOMSEARCH_SEARCH_CONFIG You can set up the search config here
3 azure_cognitiveservices_entitysearch ENTITYSEARCH_SUBSCRIPTION_KEY Your Service Key
4 azure_cognitiveservices_imagesearch IMAGESEARCH_SUBSCRIPTION_KEY Your Service Key
5 azure_cognitiveservices_newssearch NEWSSEARCH_SUBSCRIPTION_KEY Your Service Key
6 azure_cognitiveservices_spellcheck SPELLCHECK_SUBSCRIPTION_KEY Your Service Key
7 azure_cognitiveservices_textanalytics TEXTANALYTICS_SUBSCRIPTION_KEY Your Service Key
8 azure_cognitiveservices_videosearch VIDEOSEARCH_SUBSCRIPTION_KEY Your Service Key
9 azure_cognitiveservices_websearch WEBSEARCH_SUBSCRIPTION_KEY Your Service Key
10 azure_cognitiveservices_contentmoderator CONTENTMODERATOR_SUBSCRIPTION_KEY Your Service Key
CONTENTMODERATOR_TEAM_NAME You can create and get the team name here

You can set the environment variable as:

export {your key}={your value}

> [AZURE.NOTE] On Windows, use `set` instead of `export`.
  1. Run the sample.

    ruby run_samples.rb --sdk={sample_to_run}
  2. To know the possible values of sdk, you can run the following command:

    ruby run_samples.rb --help

To see the code of each example, simply look at the examples in the Samples folder. They are written to be isolated in scope so that you can see only what you're interested in.