You can setup context specific build variables in your netlify.toml
[context.production.environment]
API_ENDPOINT = "https://production.yourservice.net"
[context.staging.environment]
API_ENDPOINT = "https://staging.yourservice.net"`
More info in this support guide: