Add data to a request bodyv3.6+

Configure the plugin to use OpenAI GPT-4 to add an element to the client request body before proxying it. See Transform a request body using OpenAI for a full how-to guide with this example.

Prerequisites

  • You have an OpenAI subscription.

Environment variables

  • OPENAI_API_KEY: An API key to connect to the OpenAI API.

Set up the plugin

Add this section to your declarative configuration file:

_format_version: "3.0"
plugins:
  - name: ai-request-transformer
    config:
      prompt: In my JSON message, anywhere there is a JSON tag for a city, also add
        a country tag with the name of the country that city is in.
      transformation_extract_pattern: "{((.|\\n)*)}"
      llm:
        route_type: llm/v1/chat
        auth:
          header_name: Authorization
          header_value: Bearer ${{ env "DECK_OPENAI_API_KEY" }}
        model:
          provider: openai
          name: gpt-4
Copied to clipboard!

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!