Skip to content

Create an AI API

AI APIs enable seamless integration of AI services into applications through the WSO2 API Manager. By using the AI API feature, users can select specific AI vendors that best suit their needs. WSO2 API Manager provides built-in support for leading AI vendors like OpenAI, Azure OpenAI, and Mistral, while also allowing configuration of custom AI vendors to create AI APIs.

This guide will get you started with AI API creation using WSO2 API Manager. Thus created AI API wil be deployed into the AI Gateway. Refer to AI Gateway to get a deeper understanding on API Manager's AI Gateway capabilities.

Follow the instructions below to create an AI API using the basic flow:

Step 1: Create an AI API

  1. Login to the Publisher Portal (https://<hostname>:9443/publisher).

  2. Create an AI/LLM API by clicking on Create AI/LLM API.

    Select AI API

  3. Select the desired provider and version. Then, click Next.

    Select AI Service Provider and Version

    Tip

    The built-in AI service providers and versions will appear on relevant dropdowns. In addition to the default vendors, you can add custom AI vendors by following the custom AI vendor integration documentation.

  4. Fill in the AI API details and click Create.

    Field Sample value
    Name OpenAIAPI
    Context

    openaiapi

    The API context is used by the Gateway to identify the API. Therefore, the API context must be unique. This context is the API's root context when invoking the API through the Gateway.

    You can define the API's version as a parameter of its context by adding the {version} into the context. For example, {version}/openaiapi. The API Manager assigns the actual version of the API to the {version} parameter internally. For example, https://localhost:8243/2.3.0/openaiapi. Note that the version appears before the context, allowing you to group your APIs based on the versions.

    Version 2.3.0

    Create OpenAI API

    The overview page of the newly created API appears.

Step 2: Obtain API Key from AI Service Vendor

  1. Login to OpenAI and go to OpenAI Dashboard.
  2. Navigate to API keys section from the left menu. Then, click on Create new secret key. Provide a name for the key and click on Create secret key.

    Get OpenAI API Key

Step 3: Configure Sandbox and Production Endpoint

  1. Navigate to API ConfigurationsEndpoints.
  2. Notice the API Key Required warning against the Default Production Endpoint and Default Sandbox Endpoint. Click on Edit icon and fill in the API Key value which you obtained from Step 1 above and click on Update to save the changes.

    Note

    API Manager supports three AI/LLM vendors by default. The authorization approach of each is mentioned below:

    • MistralAI: Authorization header
    • AzureOpenAI: api-key header
    • OpenAI: Authorization header

    Note that we prepend "Bearer " to the header value that you provide when it comes to MistralAI and OpenAI since they are expecting an Authorization header.

    API Key Configuration

Now, you have successfully created an AI API. Next, deploy the API, test the API, and finally publish the API.

See Also

Learn more on the concepts that you need to know when creating a REST API: