Alamofire Error

I keep getting this error when I try to run my app:

responseValidationFailed(reason:Alamofire.AFError.ResponseValidationFailureReason.unacceptableStatusCode(code: 401))
Status code: 401

I am just trying to incorporate Mailgun into my app. I've don't=e some reaserch and people keep saying that I put in an invalid API key, but it is the correct one! Help would be much appreciated. Here's the code (obviously the API Key and domain would be filled in with my actual one):

import SwiftUI
import Alamofire
import SwiftyJSON

struct ContentView: View {
    let mailgunAPIKey = "-apikey-"
    let mailgunDomain = "-mailgundomain-"
    let recipientEmail = "email@email.com"

    @State private var userEmail = ""
    @State private var showAlert = false

    var body: some View {
        VStack {
            TextField("Your Email", text: $userEmail)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .padding()

            Button(action: {
                sendEmail()
            }) {
                Text("Send Email")
            }
        }
        .alert(isPresented: $showAlert) {
            Alert(title: Text("Success"), message: Text("Email sent successfully"), dismissButton: .default(Text("OK")))
        }
    }

    func sendEmail() {
        let parameters: [String: String] = [
            "from": userEmail,
            "to": recipientEmail,
            "subject": "Test Email",
            "text": "Hello from Mailgun!"
        ]

        AF.request("https://api.mailgun.net/v3/\(mailgunDomain)/messages",
                   method: .post,
                   parameters: parameters,
                   encoding: URLEncoding.httpBody,
                   headers: HTTPHeaders(["Authorization": "Basic \(mailgunAPIKey)"]))
            .validate()
            .responseJSON { response in
                switch response.result {
                case .success(let value):
                    if let json = value as? [String: Any] {
                        print(json)
                        showAlert = true // Show the alert on success
                    } else {
                        print("Error parsing JSON response")
                    }
                case .failure(let error):
                    print(error)
                    if let statusCode = response.response?.statusCode {
                        print("Status code: \(statusCode)")
                    }
                    // Handle error
                }
            }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}