watsonx-ai-invoke
Use the watsonx.ai invoke policy to invoke watsonx.ai operations.
Gateway support
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
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.
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:
If the request payload contains a |
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