For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
GitHub Copilot
Authenticate to GitHub Copilot with a token from a Kubernetes Secret.
About
The Copilot LLM provider sends requests to the GitHub Copilot API with a token from a Kubernetes Secret. The provider sets the upstream endpoint and the protocol headers that the Copilot API expects.
In Kubernetes, configure ai.provider.copilot on an AgentgatewayBackend and supply the token through policies.auth.secretRef. The standalone backendAuth: copilot method discovers credentials on the gateway host. Kubernetes uses an explicit Secret instead.
Note
Kubernetes Copilot support requires version 1.7 or later. Use CRDs, controller, and data-plane builds that include this support.
Before You Begin
- Install and set up an agentgateway proxy.
Set up an agentgateway proxy. The example uses the
agentgateway-proxyGateway.Have a credential accepted by the Copilot API for an account with access to the model you want to use. Agentgateway does not obtain, exchange, or refresh this credential. An arbitrary GitHub personal access token might not work.
Configure Copilot Backend Authentication
Save your Copilot token in an environment variable.
export COPILOT_TOKEN='<your-copilot-token>'Create a Secret that holds the token. The default resolver reads the
Authorizationkey.kubectl create secret generic copilot-token \ --namespace agentgateway-system \ --from-literal=Authorization="$COPILOT_TOKEN"Create an AgentgatewayBackend that selects the Copilot provider and references the Secret.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayBackend metadata: name: copilot namespace: agentgateway-system spec: ai: provider: copilot: {} policies: ai: routes: /v1/chat/completions: Completions /v1/messages: Messages /v1/responses: Responses auth: secretRef: name: copilot-token EOFReview the following table to understand this configuration. For more information, see the API reference.
Field Description ai.provider.copilotSelects the Copilot LLM provider. The default upstream is api.githubcopilot.com:443, with TLS verification.ai.provider.copilot.modelOptional model override. When omitted, the provider uses the model from the request. policies.ai.routesMaps incoming paths to API formats. The example enables Chat Completions, Messages, and Responses. policies.auth.secretRef.nameName of the credential Secret in the backend’s namespace. Copilot also works with an AgentgatewayModel. Set
provider: Copilotand supply the Secret throughspec.policies.auth.secretRef.Create an HTTPRoute that forwards requests to the Copilot backend.
kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: copilot namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy rules: - backendRefs: - group: agentgateway.dev kind: AgentgatewayBackend name: copilot matches: - path: type: Exact value: /v1/chat/completions - path: type: Exact value: /v1/messages - path: type: Exact value: /v1/responses EOFGet the gateway address.
Tip
Kind cluster? Kind does not support
LoadBalancerservices by default. To use this option with a Kind cluster, install and runcloud-provider-kind.The following command reads the LoadBalancer IP address or hostname, whichever your cloud provider assigns.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy \ -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo "Gateway address: $INGRESS_GW_ADDRESS"Send a request with a model that your Copilot account can use. The following example uses
gpt-4.1. For local testing, setINGRESS_GW_ADDRESS=localhost:8080in the terminal where you send the request.curl --fail-with-body "http://$INGRESS_GW_ADDRESS/v1/chat/completions" \ --header 'Content-Type: application/json' \ --data '{ "messages": [ { "content": "Explain how AI works in simple terms.", "role": "user" } ], "model": "gpt-4.1" }'The route also accepts
/v1/messagesand/v1/responseswith their corresponding request bodies. Choose an API format that the model supports. Set"stream": truein the request body for streaming.
The example uses the sample gateway’s HTTP listener. Configure client authentication and authorization before exposing it to other callers. Copilot requests use the existing LLM policies, metrics, and tracing. Configure caller identity separately for per-user attribution.
Where Agentgateway Finds the Token
The controller resolves policies.auth.secretRef in the namespace of the AgentgatewayBackend. It reads the Authorization key by default and sends the value as a bearer token. That key accepts a bare credential or one prefixed with Bearer .
To use another data key, set policies.auth.secretRef.key. Store the bare token under a custom key. Only the Authorization key strips an existing Bearer prefix before the gateway adds it again.
An explicit Secret takes precedence over credentials on the gateway host. A missing Secret, missing key, or empty credential reports a configuration error and keeps an explicit empty backend credential. Requests cannot fall back to environment variables, Copilot configuration files, or GitHub CLI credentials on the gateway host.
Note
The controller watches for Secret changes and updates the backend after reconciliation. Updating the token does not require a gateway restart. Agentgateway does not renew the token, and restarting the gateway does not extend its validity.
To revoke a credential, use its issuer’s revocation process. Deleting or invalidating the Secret prevents host-credential fallback after reconciliation. It does not revoke the credential at GitHub or cancel requests already in flight.
What Agentgateway Sends
The gateway writes the token to the Authorization header. The Copilot provider adds the following protocol headers after backend transformations and request-header modifiers.
| Header | Value |
|---|---|
authorization | Bearer followed by the token. |
content-type | application/json. |
editor-version | agentgateway/ followed by the version of the binary. |
openai-intent | conversation-agent. |
x-github-api-version | The Copilot API version that this release targets. |
x-initiator | agent. |
x-interaction-type | conversation-agent. |
The provider supplies these headers automatically. No manual header configuration is needed.
Warning
The provider sets content-type to application/json on every request and overwrites the value that the client sent. Use it for JSON API requests.
Troubleshoot
Inspect the backend status for configuration errors.
kubectl get AgentgatewayBackend copilot \
--namespace agentgateway-system -o yaml| Symptom | Cause and Resolution |
|---|---|
The API server rejects the copilot provider field. | The installed CRDs do not include Kubernetes Copilot support. Use matching CRDs, controller, and data-plane builds that include the provider. |
| The backend rejects the token although the Secret resolves. | The credential is expired, is not accepted by the Copilot API, or lacks access to the selected model. Confirm the credential and account entitlement with GitHub. Upstream authentication and entitlement errors reach the client. |
| The backend reports a missing Secret. | The referenced Secret does not exist in the backend’s namespace. Check policies.auth.secretRef.name and create the Secret in that namespace. |
The backend reports missing Authorization value. | The Secret’s Authorization key is missing, empty, or contains only the Bearer scheme. Supply a valid credential, or set secretRef.key to the key that holds it. |
| The request fails with an unsupported conversion error. | The selected model does not accept the requested API format. Choose a model and request format that work together. |
| The upstream rejects the request body. | The provider sends content-type: application/json. Send a JSON body in the format expected by /v1/chat/completions, /v1/messages, or /v1/responses. |