{
  "repo": "tidbcloud/inference-service",
  "binary": "server",
  "binary_path": "cmd/server/main.go",
  "dependencies": {
    "Runtime InferenceServiceLifecycle.Startup": {
      "infrastructure": {
        "config": {
          "conditions": [
            "Always"
          ],
          "operations": [
            {
              "operation": "LOAD CONFIG",
              "trigger": "Initialize defaults, optional YAML overrides, optional .env file, and env overrides before command execution",
              "conditions": [
                "Always"
              ],
              "implementation": "cobra.OnInitialize(initConfig) -> config.LoadConfig(cfgFile)"
            }
          ]
        }
      },
      "services": []
    },
    "Runtime InferenceServiceLifecycle.Setup": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Only when storage.usageDataDir does not start with s3://"
          ],
          "operations": [
            {
              "operation": "MKDIR",
              "trigger": "Prepare the local usage data directory before loading persisted usage state",
              "conditions": [
                "storage.usageDataDir is a local path"
              ],
              "implementation": "service.NewUsageService -> os.MkdirAll(storageConfig.UsageDataDir, 0755)"
            },
            {
              "operation": "READ FILE",
              "trigger": "Load the previous usage snapshot from local disk if it exists",
              "conditions": [
                "storage.usageDataDir is a local path"
              ],
              "implementation": "LocalStorageBackend.Load -> os.ReadFile(filePath)"
            }
          ]
        },
        "s3": {
          "conditions": [
            "Only when storage.usageDataDir starts with s3://"
          ],
          "operations": [
            {
              "operation": "GET BUCKET REGION",
              "trigger": "Resolve the bucket region before creating the S3 client",
              "conditions": [
                "storage.usageDataDir starts with s3://"
              ],
              "implementation": "service.NewS3StorageBackend -> manager.GetBucketRegion(context.TODO(), s3client, bucketName)"
            },
            {
              "operation": "HEAD BUCKET",
              "trigger": "Verify the target S3 bucket is accessible",
              "conditions": [
                "storage.usageDataDir starts with s3://"
              ],
              "implementation": "service.NewS3StorageBackend -> client.HeadBucket(...)"
            },
            {
              "operation": "GET OBJECT",
              "trigger": "Load the previous usage snapshot from S3 if it exists",
              "conditions": [
                "storage.usageDataDir starts with s3://"
              ],
              "implementation": "S3StorageBackend.Load -> client.GetObject(...)"
            }
          ]
        }
      },
      "services": []
    },
    "Runtime InferenceServiceLifecycle.ServeHTTP": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Only when storage.usageDataDir does not start with s3:// and usage data changed since the last save"
          ],
          "operations": [
            {
              "operation": "WRITE FILE",
              "trigger": "Persist the current usage snapshot during periodic save and graceful shutdown",
              "conditions": [
                "storage.usageDataDir is a local path",
                "usage data changed since lastSavedData"
              ],
              "implementation": "UsageService.saveData -> LocalStorageBackend.Save -> os.WriteFile(tempFile); os.Rename(tempFile, filePath)"
            }
          ]
        },
        "s3": {
          "conditions": [
            "Only when storage.usageDataDir starts with s3:// and usage data changed since the last save"
          ],
          "operations": [
            {
              "operation": "PUT OBJECT",
              "trigger": "Persist the current usage snapshot during periodic save and graceful shutdown",
              "conditions": [
                "storage.usageDataDir starts with s3://",
                "usage data changed since lastSavedData"
              ],
              "implementation": "UsageService.saveData -> S3StorageBackend.Save -> client.PutObject(...)"
            }
          ]
        }
      },
      "services": []
    },
    "Runtime InferenceServiceLifecycle.StartMetricsServer": {
      "infrastructure": {},
      "services": []
    },
    "HTTP POST /api/v1/inference/embeddings/:tenantId": {
      "infrastructure": {},
      "services": [
        {
          "name": "aws-bedrock-runtime",
          "target_interface": "POST /model/{modelId}/invoke",
          "operation_type": "http_post",
          "target_repo": "aws/bedrock-runtime",
          "conditions": [
            "tenantId path parameter is not empty",
            "request body is valid JSON",
            "req.Model exists in config.Global().Models",
            "len(req.Texts) is between 1 and 100",
            "usageService.CheckQuota(tenantID, 1) succeeds",
            "If Server.CheckServiceAPIKey is configured, Authorization bearer token must match it"
          ],
          "operations": [
            {
              "operation": "HTTP POST",
              "trigger": "Invoke Titan embedding generation for each input text concurrently",
              "conditions": [
                "modelConfig.IsTitanModel() == true"
              ],
              "implementation": "BedrockService.generateTitanEmbeddings / generateSingleTitanEmbedding -> resty.Client.R().Post(url)"
            },
            {
              "operation": "HTTP POST",
              "trigger": "Invoke Cohere embedding generation in a single batched request",
              "conditions": [
                "modelConfig.IsCohereModel() == true"
              ],
              "implementation": "BedrockService.generateCohereEmbeddings -> resty.Client.R().Post(url)"
            }
          ]
        }
      ]
    },
    "HTTP GET /api/v1/inference/quota_usage/:tenantId": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /api/v1/inference/quota_usage": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /healthz": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /version": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /swagger/*any": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /metrics": {
      "infrastructure": {},
      "services": []
    }
  },
  "notes": [
    "The request path records usage in memory only; persistence happens asynchronously in UsageService.periodicSave and during graceful shutdown via UsageService.Close.",
    "Quota checking is intentionally optimistic in the handler: it checks cost 1 before the real Bedrock cost is known, then records the actual micro-dollar usage after the provider response."
  ]
}
