{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.krakend.io/schema/v2.11/ai/openai.json",
  "title": "OpenAI integration",
  "description": "Connect to OpenAI's GPT models easily by providing your API key and optional parameters.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/mistral/",
  "type": "object",
  "maxProperties": 1,
  "minProperties": 1,
  "properties": {
    "v1": {
      "title": "Version v1",
      "description": "All settings depend on  a specific version, as the vendor might change the API over time.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
      "required": [ "credentials", "variables" ],
      "properties": {
        "credentials": {
          "title": "API Key",
          "description": "Your OpenAI API key. You can set it as an environment variable for better security.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
          "examples": [ "sk-xxxx" ],
          "type": "string"
        },
        "debug": {
          "title": "Debug Mode",
          "description": "Enables the debug mode to log activity for troubleshooting. Do not set this value to true in production as it may log sensitive data.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
          "default": false,
          "type": "boolean"
        },
        "input_template": {
          "title": "Input Template",
          "description": "A path to a custom [Go template](https://pkg.go.dev/text/template) that sets the payload format sent to OpenAI. You don't need to set this value unless you want to override the default template making use of all the `variables` listed in this configuration.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
          "type": "string"
        },
        "output_template": {
          "title": "Output Template",
          "description": "A path to a custom [Go template](https://pkg.go.dev/text/template) that sets how the response from OpenAI is transformed before being sent to the client. The default template extracts the text from the first choice returned by OpenAI so in most cases you don't need to set a custom output template.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
          "type": "string"
        },
        "variables": {
          "title": "Template Variables",
          "description": "The variables specific to the OpenAI usage that are used to construct the payload.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
          "type": "object",
          "required": [ "model" ],
          "properties": {
            "extra_payload": {
              "title": "Extra Payload",
              "description": "A map of additional payload attributes you want to use in your custom `input_template` (this payload is not used in the default template). The attributes set here are accessible in your custom template as `{{ .variables.extra_payload.yourchosenkey }}`. This option helps adding rare customization and future attributes.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
              "type": "object"
            },
            "max_output_tokens": {
              "title": "Max Output Tokens",
              "description": "An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens. Setting this value to `0` does not set any limit.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
              "type": "integer"
            },
            "model": {
              "title": "Model Name",
              "description": "The name of the OpenAI model you want to use. The value you provide is passed as is to OpenAI and KrakenD does not prove if the model is currently accepted by the vendor. Check the available models on OpenAI documentation.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
              "examples": [ "gpt-5-nano", "gpt-4" ],
              "type": "string"
            },
            "temperature": {
              "title": "Temperature",
              "description": "What sampling temperature to use, between `0` and `2`. Higher values like `0.8` will make the output more random, while lower values like `0.2` will make it more focused and deterministic.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
              "type": "number",
              "maximum": 2,
              "minimum": 0
            },
            "top_p": {
              "title": "Top P",
              "description": "The nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
              "type": "number",
              "maximum": 1,
              "minimum": 0
            },
            "truncation": {
              "title": "Truncation Strategy",
              "description": "The strategy to use when truncating messages to fit within the model's context length (, the model will truncate the response to fit the context window by dropping items from the beginning of the conversation.\n\nSee: https://www.krakend.io/docs/enterprise/ai-gateway/openai/",
              "default": "disabled",
              "enum": [ "auto", "disabled" ]
            }
          }
        }
      },
      "patternProperties": {
        "^[@$_#]": {}
      },
      "additionalProperties": false
    }
  },
  "patternProperties": {
    "^[@$_#]": {}
  },
  "additionalProperties": false
}
