DataPower API Gateway
only

watsonx-ai-invoke

Use the watsonx.ai invoke policy to invoke watsonx.ai operations.

Gateway support

Table 1. Table showing which gateways support this policy, and the corresponding policy version
Gateway Policy version
DataPower® API Gateway 2.0.0

This topic describes how to configure the policy in your OpenAPI source; for details on how to configure the policy in the assembly user interface, see watsonx.ai invoke.

About

The watsonx.ai invoke policy provides access to three watsonx.ai operations:
  • POST /text_generation
  • POST /text_tokenization
  • GET /foundation_model_specs

Properties

The following table lists the policy properties, indicates whether a property is required, specifies the valid and default values for input, and specifies the data type of the values.

Table 2. watsonx.ai invoke policy properties
Property label Required Description Data type
version Yes The policy version number. You must specify a version for the policy that is compatible with the gateway that you are using. When the API is published, if the version is incompatible with the gateway, a validation error is thrown that specifies the available versions. string
title No The title of the policy; the default value is watsonx-ai-invoke text generation. string
description No A description of the policy. string
operation Yes The watsonx.ai operation to invoke; must be one of the following operations:
  • POST text_generation

    An HTTP POST operation for /text_generation. See Infer text in the watsonx.ai documentation for sample request and response examples.

  • POST text_tokenization

    An HTTP POST operation for /text_tokenization. See Text tokenization in the watsonx.ai documentation for sample request and response examples.

  • GET foundation_model_specs

    An HTTP GET operation for /foundation_model_specs. See List the available foundation models in the watsonx.ai documentation for sample response examples.

If the request payload contains a project_id property, it is ignored and the policy's own project_id property is used.

string
op-version Yes The watsonx.ai API operation version, using the format yyyy-mm-dd.

To see the available version dates, refer to Active Version Dates in the watsonx.ai API documentation. For information on API versioning in watsonx.ai, see Versioning in the same documentation.

string
project_id Yes The ID of the watsonx.ai project used for resolving API requests. string
region Yes The IBM Cloud region where watsonx.ai requests are sent. string
enable_cache No Response caching is enabled by default to optimize API performance; however, you can disable it if needed for your API.

When response caching is enabled, then when a request is sent to the watsonx.ai service, the response cache is inspected to determine if the request payload has an associated cached response. If so, that cached response and its associated HTTP response headers are placed into the DataPower API Gateway context message specified by the output property.

If there is no cached response, the request is passed to the watsonx.ai service, and the response is cached for subsequent operations using the time-to-live specified in the cache_ttl property.

boolean
cache_ttl No The duration of the cache (the time-to-live). The minimum duration is 60 seconds and the maximum duration is 86400 seconds (1 day) -- any value outside of that range will fail validation when the API is published, even if the value is accepted in this field. integer
cache_scope No A string that adds uniqueness to the key used to store a cached response. Adding a cache scope enables the same request to be saved in multiple cache entries. string
output No The name of the DataPower API Gateway context message that receives the watsonx.ai response. By default, this property uses message as the value, which enables the response to be accessible by subsequent API policies in message.body. string

Example


- watsonx-ai-invoke:
    version: 2.0.0
    title: watsonx-ai-invoke text generation
    description: get an AI response to the provided prompt
    region: us-south
    operation: POST text_generation
    op-version: '2024-03-14'
    enable_cache: true
    cache_ttl: 60
    project_id: $(watsonx-ai-projectid)
    output: watsonxaiResponse
    cache_scope: somesaltkey