{
  "post": {
    "tags": ["Credentials"],
    "summary": "Save or update credentials",
    "description": "Save or update encrypted credentials for AI, Color Conversion, or Remove Background services.\n\n**Flow:**\n1. **First call (no encryptionKey):**\n   - Generate a new UUID encryption key\n   - Encrypt credentials with this UUID\n   - Save encrypted credentials to file\n   - Return the encryption key (UUID) in response\n   - **Store this key securely** - it's required for all future API calls\n\n2. **Subsequent calls (with encryptionKey):**\n   - Use the provided encryption key to decrypt existing credentials\n   - Merge new data with existing data (only provided fields are updated)\n   - Re-encrypt with the same key\n   - Save updated credentials\n   - Return the same encryption key\n\n**Usage:**\n- The returned encryption key must be sent in the `API-KEY` header for all AI and image processing API requests\n- Each credential set is encrypted with its own unique encryption key (UUID)\n- You can save multiple credential types (ai, colorConversion, removeBackground) in a single call\n- At least one credential type must be provided\n\n**Security:**\n- Credentials are encrypted using AES-256-CBC\n- The encryption key (UUID) is used to derive the encryption key\n- Credentials are stored in an encrypted file on the server\n- Rate limiting is applied to prevent abuse",
    "requestBody": {
      "required": true,
      "content": {
        "application/json": {
          "schema": {
            "$ref": "../../components/schemas/SaveCredentialRequest.json"
          }
        }
      }
    },
    "responses": {
      "201": {
        "summary": "Credentials created successfully.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Credentials saved successfully"
                },
                "data": {
                  "type": "object",
                  "properties": {
                    "encryptionKey": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Encryption key for future updates. Store this securely.",
                      "example": "a2d950aa-2468-46bb-b443-1a405a184ee0"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "200": {
        "summary": "Credentials updated successfully.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Credentials updated successfully"
                },
                "data": {
                  "type": "object",
                  "properties": {
                    "encryptionKey": {
                      "type": "string",
                      "format": "uuid",
                      "example": "a2d950aa-2468-46bb-b443-1a405a184ee0"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "304": {
        "summary": "No changes made.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Credentials are already in use and no changes were made"
                },
                "data": {
                  "type": "object",
                  "properties": {
                    "encryptionKey": {
                      "type": "string",
                      "format": "uuid",
                      "example": "a2d950aa-2468-46bb-b443-1a405a184ee0"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "400": {
        "summary": "Bad Request.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "At least one credential type (ai, colorConversion, removeBackground) must be provided with data"
                }
              }
            }
          }
        }
      },
      "404": {
        "summary": "Not Found.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Credential with provided encryption key not found"
                }
              }
            }
          }
        }
      },
      "429": {
        "summary": "Too Many Requests.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Too many requests from this IP, please try again later"
                }
              }
            }
          }
        }
      },
      "500": {
        "summary": "Internal Server Error.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Internal Server Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
