How to call Azure Cost Management API with a ClientType set

Amber Nguyen 20 Reputation points
2025-07-14T18:14:16.1933333+00:00

I am attempting to use the Azure cost management Go SDK and need to call the Cost Management API many times. The rate limit for API calls is higher when a ClientType is specified, so I was wondering how to go about including the ClientType in the Usage function.

Developer technologies | Visual Studio | Testing
0 comments No comments
{count} votes

Accepted answer
  1. Gade Harika (INFOSYS LIMITED) 330 Reputation points Microsoft External Staff
    2025-07-16T03:54:06.9833333+00:00

    Thank you for sharing the details

    you're absolutely right that setting a ClientType header can significantly increase your API rate limits when using the Azure Cost Management API.

    Here’s how to include the ClientType header when using the Azure Go SDK:

    How to Set ClientType in Go SDK

    When creating your Cost Management client, you can pass custom headers like this:

    import (

    "github.com/Azure/azure-sdk-for-go/sdk/azcore"
    
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    
    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement"
    

    )

    cred, err := azidentity.NewDefaultAzureCredential(nil)

    if err != nil {

    log.Fatalf("failed to obtain credential: %v", err)
    

    }

    clientOptions := &azcore.ClientOptions{

    Telemetry: azcore.TelemetryOptions{
    
        ApplicationID: "my-custom-client-type", //  This sets ClientType
    
    },
    

    }

    client, err := armcostmanagement.NewQueryClient(subscriptionID, cred, clientOptions)

    if err != nil {

    log.Fatalf("failed to create client: %v", err)
    

    }

    This sets the ClientType via the ApplicationID field, which is used internally by Azure to identify your client and apply the appropriate rate limits.

    Let me know if the issue persists after following these steps. I’ll be happy to assist further if needed.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.