Why ServiceRegister of Agent do not have a parameter for ACL token?

Source: https://github.com/hashicorp/consul/blob/main/api/agent.go
func (a *Agent) ServiceRegister(service *AgentServiceRegistration) do not have a param of token.
func ServiceDeregister also do not have the ACL token.
Is this a bug?

Hi @chigonhx,

I don’t believe this is a bug. You can configure the API client to use a token when making requests by passing in a custom Config.

Here’s an example.

package main

import (


func main() {

	// Get token from environment variable
	token := os.Getenv("CONSUL_HTTP_TOKEN")
	if token == "" {
		fmt.Println("No token was provided. Cannot authenticate to Consul.")

	config := api.Config{
		Token: token,

	// Get a new client
	client, err := api.NewClient(&config)
	if err != nil {

	service_name := "my-service"
	service_port := 1234

	svc_reg := &api.AgentServiceRegistration{
		Name: service_name,
		Port: service_port,

	err = client.Agent().ServiceRegister(svc_reg)
	if err != nil {