# Save the AI key (/id/growsocmed/docs/api-reference/ai-agents/save-ai-connection)

Save the AI provider key (checked first; stored encrypted)

PUT /ai/connection

```json
{
  "tags": [
    "AI agents"
  ],
  "summary": "Save the AI key",
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "provider": {
              "type": "string",
              "enum": [
                "anthropic",
                "openai",
                "gemini",
                "openrouter",
                "custom"
              ]
            },
            "base_url": {
              "type": [
                "string",
                "null"
              ],
              "maxLength": 300,
              "format": "uri"
            },
            "api_key": {
              "type": "string",
              "minLength": 8,
              "maxLength": 500
            }
          },
          "required": [
            "provider",
            "api_key"
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OK",
      "content": {
        "application/json": {
          "schema": {}
        }
      }
    }
  },
  "operationId": "save-ai-connection",
  "description": "Save the AI provider key (checked first; stored encrypted)"
}
```