diff --git a/algolia/search/generate_secured_api_key.go b/algolia/search/generate_secured_api_key.go
index <HASH>..<HASH> 100644
--- a/algolia/search/generate_secured_api_key.go
+++ b/algolia/search/generate_secured_api_key.go
@@ -11,15 +11,19 @@ import (
 	"github.com/algolia/algoliasearch-client-go/algolia/transport"
 )
 
-func GenerateSecuredAPIKey(apiKey string, opts ...interface{}) (key string, err error) {
+func GenerateSecuredAPIKey(apiKey string, opts ...interface{}) (string, error) {
+	h := hmac.New(sha256.New, []byte(apiKey))
+
 	message := transport.URLEncode(newSecuredAPIKeyParams(opts...))
+	_, err := h.Write([]byte(message))
+	if err != nil {
+		return "", err
+	}
 
-	h := hmac.New(sha256.New, []byte(apiKey))
-	h.Write([]byte(message))
-	securedKey := hex.EncodeToString(h.Sum(nil))
+	checksum := hex.EncodeToString(h.Sum(nil))
+	key := base64.StdEncoding.EncodeToString([]byte(checksum + message))
 
-	key = base64.StdEncoding.EncodeToString([]byte(securedKey + message))
-	return
+	return key, nil
 }
 
 type securedAPIKeyParams struct {
fixed: correctly handle HMAC error on writing checksum