copilotApiBaseUrlFromToken function
The Copilot API base URL carried INSIDE the token, if any
(pi getBaseUrlFromToken parity): Copilot tokens embed
proxy-ep=proxy.<tenant>.githubcopilot.com (individual/business/
enterprise tenants, incl. dedicated enterprise endpoints); the API
host is the proxy host with the proxy. prefix swapped for api..
Null when the token carries no proxy-ep (older/individual tokens —
the caller keeps the configured base URL).
Implementation
String? copilotApiBaseUrlFromToken(String token) {
final match = RegExp(r'proxy-ep=([^;]+)').firstMatch(token);
if (match == null) return null;
final proxyHost = match.group(1)!;
final apiHost = proxyHost.startsWith('proxy.')
? 'api.${proxyHost.substring('proxy.'.length)}'
: proxyHost;
return 'https://$apiHost';
}