Skip to main content

Capture CustomerIDs

Capturing CustomerIDs is not required, but is highly recommended. By setting a CustomerID you can associate requests to your customers/users, which powers the filters needed to build a customer-facing API dashboard.

tip

If you are planning to build a developer experience portal, then it's important to pick a CustomerID that is stable, and connected to your identity system. When users login to your portal, Speakeasy will then be able to filter the data to just those relevant to the user.

For example: CustomerID is preferable to api_key because an API key can be rotated and is therefore unstable.

To associate requests with a customer ID, you need to instantiate the Speakeasy middleware in your handler functions and then set the CustomerID field. Below are per language examples of setting a CustomerID in a handler function.

func MyHandler(w http.ResponseWriter, r *http.Request) {
ctrl := speakeasy.MiddlewareController(req)
ctrl.CustomerID("a-customers-id") // This customer ID will be used to associate this instance of a request with your customers/users

// the rest of your handlers code
}