All Products
Search
Document Center

API Gateway:AI-assisted plugin development

Last Updated:Jun 18, 2025

This topic describes how to use AI large language models (LLMs) to automatically generate plugin code based on your input requirements.

Overview

To address diverse gateway usage needs while simplifying plugin development, AI Gateway provides an end-to-end plugin generation capability powered by LLMs. By describing plugin logic in natural language, you can initiate automated plugin generation to effortlessly fulfill customized gateway scenario requirements.

Describe requirements in natural language

AI Gateway generates plugin code based on your natural language requirements, combined with automated code compilation and testing for end-to-end plugin development. To improve accuracy and clarify development tasks for the LLM, structure your requirements as shown in the example below:

# The request header handler
Return a fixed string to all incoming requests and allow the string to be modified.
# The request body handler
None
# The response header handler
None
# The response body handler
None
Important

The LLM evaluates requirement validity. If any of the requirements are deemed impractical, the process terminates with improvement suggestions. Then, revise your requirements accordingly.

Plugin basic code structure

Gateway plugin development involves two aspects:

  • Configuration parsing: reads the input configurations of the plugin.

  • Handler function: writes functions for request header handling, request body handling, response header handling, and response body handling.

The following example shows the code of an empty plugin in Go:

type MyConfig struct {
    // config items
}

func parseConfig(json gjson.Result, config *MyConfig, log wrapper.Log) error {
    // parse config form json
    return nil
}

// The request header handler
func onHttpRequestHeaders(ctx wrapper.HttpContext, config MyConfig, log wrapper.Log) types.Action {}

// The request body handler
func onHttpRequestBody(ctx wrapper.HttpContext, config MyConfig, body []byte, log wrapper.Log) types.Action {}

// The response header handler
func onHttpResponseHeaders(ctx wrapper.HttpContext, config MyConfig, log wrapper.Log) types.Action {}

// The response body handler
func onHttpResponseBody(ctx wrapper.HttpContext, config MyConfig, body []byte, log wrapper.Log) types.Action {}

Plugin generation and debugging

The LLM attempts to generate complete plugin code based on your requirements. Upon successful generation, the code is automatically imported into WebIDE for functional validation and code adjustments based on your actual needs.