{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://runninglake.com/schema/v1alpha1/providerconnection.json",
  "title": "ProviderConnection",
  "description": "A ProviderConnection as RunningLake's configuration repository declares it, at providerconnections/<name>.yaml. Generated from the Go types the control plane decodes this file into, so it checks the shape the gate reads — field names and types, and which fields may exist. The gate also applies rules no schema can express — required fields inside spec among them — so a file this schema accepts can still be refused by `rl diff`. Take #/properties/spec for the spec alone.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "apiVersion",
    "kind",
    "metadata"
  ],
  "properties": {
    "apiVersion": {
      "type": "string",
      "const": "runninglake.io/v1alpha1",
      "description": "The config schema's version, which is independent of the HTTP API's (rule unsupported-api-version)."
    },
    "kind": {
      "type": "string",
      "const": "ProviderConnection",
      "description": "The kind this file declares. A kind that disagrees with the file's path is refused (rule kind-mismatch)."
    },
    "metadata": {
      "required": [
        "name"
      ],
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z0-9_-]{1,63}$",
          "description": "The resource's name, which is also its path segment. It must be the name this file's path gives it (rule name-mismatch)."
        },
        "labels": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "annotations": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      }
    },
    "spec": {
      "description": "ProviderConnectionSpec is one AI provider a project may call: which kind of provider it is, where it is, which stored credential it signs in with, and the models it offers with your own price for each. It is the part of a provider that is not secret. The key is entered once in AI settings, kept under a name, and this file names it; a field that reads like a key or a token is refused. A connection is recorded and checked here, and nothing calls the provider through it yet, so it routes no model call today.",
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "provider": {
          "description": "Provider is the kind of provider: anthropic, openai, openai_compatible, google_gemini, azure_openai, bedrock or vertex. A kind this build cannot call yet is accepted here and refused where it would be used.",
          "type": [
            "string",
            "null"
          ]
        },
        "credential": {
          "description": "Credential is the name of the organisation's stored credential this connection signs in with (a lower-case name of letters, digits, - and _). A connection to a kind that signs in with a cloud identity (bedrock, vertex) names none.",
          "type": [
            "string",
            "null"
          ]
        },
        "origin": {
          "description": "Origin is where the provider is reached: https, a lower-case host and an optional port, with no path. Left out, the kind's own address is used. A kind with an address of its own (anthropic, openai) ignores nothing: naming one for them is refused.",
          "type": [
            "string",
            "null"
          ]
        },
        "region": {
          "description": "Region is the provider's region as the provider spells it, or global for a provider reached through a direct API. Left out reads as global.",
          "type": [
            "string",
            "null"
          ]
        },
        "apiVersion": {
          "description": "APIVersion is the provider's own API version word (Azure's, for instance).",
          "type": [
            "string",
            "null"
          ]
        },
        "models": {
          "description": "Models are the models this connection offers, 1 to 50, each with the customer's price.",
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "description": "ID is the model's id as the provider spells it.",
                "type": [
                  "string",
                  "null"
                ]
              },
              "priceMicroCents": {
                "description": "PriceMicroCents is what a million units of each class cost, in micro-cents (a millionth of a cent), as whole numbers. One dollar for a million tokens is 100000000. A class left out is unset, not zero.",
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "properties": {
                  "input": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -9223372036854775808,
                    "maximum": 9223372036854775807
                  },
                  "output": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -9223372036854775808,
                    "maximum": 9223372036854775807
                  },
                  "cacheRead": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -9223372036854775808,
                    "maximum": 9223372036854775807
                  },
                  "cacheWrite": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": -9223372036854775808,
                    "maximum": 9223372036854775807
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
