You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DOC-2034: Document OIDC authentication for AI Gateway agent connections (#516)
* DOC-2034: Document OIDC authentication for AI Gateway agent connections
Add OIDC (OAuth 2.0 client_credentials grant) as a production
authentication option alongside the existing API key quick-start.
Includes service account setup, OIDC client configuration with
tabbed examples (cURL, Python, Node.js), token lifecycle guidance,
rp-aigw-id header in cURL examples, and troubleshooting updates.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fixes
* DOC-2034: Make OIDC the only auth method for AI Gateway
Remove the Quickstart (API key) section and make OIDC the sole
authentication path, since API keys are not supported. Move SDK
examples into the OIDC flow and update all references accordingly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* DOC-2034: Fix remaining API token references to say OIDC token
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* DOC-2034: Address PR review comments for OIDC auth documentation
- Reword OIDC intro to clarify service account credential flow
- Add discovery URL explanation after OIDC config table
- Update Python authlib example to use metadata discovery
- Correct authlib token caching note to describe actual behavior
- Clarify that AI Gateway does not auto-renew tokens
- Update token lifecycle authlib bullet to match new guidance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* incorporate doc review feedback
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
The discovery URL returns OIDC metadata, including the token endpoint and other configuration details. Use an OIDC client library that supports metadata discovery (such as `openid-client` for Node.js) so that endpoints are resolved automatically. If your library does not support discovery, you can fetch the discovery URL directly and extract the required endpoints from the JSON response.
This example performs a one-time token fetch. For automatic token renewal on subsequent requests, pass `token_endpoint` to the `OAuth2Session` constructor. Note that for `client_credentials` grants, `authlib` obtains a new token rather than using a refresh token.
118
+
--
119
+
120
+
Node.js (openid-client)::
121
+
+
122
+
[source,javascript]
123
+
----
124
+
import { Issuer } from 'openid-client';
125
+
126
+
const issuer = await Issuer.discover(
127
+
'https://auth.prd.cloud.redpanda.com'
128
+
);
129
+
130
+
const client = new issuer.Client({
131
+
client_id: '<client-id>',
132
+
client_secret: '<client-secret>',
133
+
});
134
+
135
+
const tokenSet = await client.grant({
136
+
grant_type: 'client_credentials',
137
+
audience: 'cloudv2-production.redpanda.cloud',
138
+
});
139
+
140
+
const accessToken = tokenSet.access_token;
141
+
----
142
+
====
143
+
144
+
=== Make authenticated requests
145
+
146
+
Requests require two headers:
147
+
148
+
* `Authorization: Bearer <token>` - your OIDC access token
149
+
* `rp-aigw-id: <gateway-id>` - your AI Gateway ID
38
150
39
151
Set these environment variables for consistent configuration:
IMPORTANT: Your agent is responsible for refreshing tokens before they expire. OIDC access tokens have a limited time-to-live (TTL), determined by the identity provider, and are not automatically renewed by the AI Gateway. Check the `expires_in` field in the token response for the exact duration.
248
+
249
+
* Proactively refresh tokens at approximately 80% of the token's TTL to avoid failed requests.
250
+
* `authlib` (Python) can handle token renewal automatically when you pass `token_endpoint` to the `OAuth2Session` constructor. For `client_credentials` grants, it obtains a new token rather than using a refresh token.
251
+
* For other languages, cache the token and its expiry time, then request a new token before the current one expires.
252
+
136
253
== Model naming convention
137
254
138
255
When making requests through AI Gateway, use the `vendor/model_id` format for the model parameter:
@@ -196,7 +313,7 @@ from openai import OpenAI, OpenAIError
196
313
197
314
client = OpenAI(
198
315
base_url=os.getenv("REDPANDA_GATEWAY_URL"),
199
-
api_key=os.getenv("REDPANDA_API_KEY"),
316
+
api_key=access_token, # OIDC access token
200
317
)
201
318
202
319
try:
@@ -210,7 +327,7 @@ except OpenAIError as e:
210
327
if e.status_code == 400:
211
328
print("Bad request - check model name and parameters")
212
329
elif e.status_code == 401:
213
-
print("Authentication failed - check API token")
330
+
print("Authentication failed - check OIDC token")
214
331
elif e.status_code == 404:
215
332
print("Model not found - check available models")
216
333
elif e.status_code == 429:
@@ -224,7 +341,7 @@ except OpenAIError as e:
224
341
Common error codes:
225
342
226
343
* *400*: Bad request (invalid parameters, malformed JSON)
227
-
* *401*: Authentication failed (invalid or missing API token)
344
+
* *401*: Authentication failed (invalid or expired OIDC token)
228
345
* *403*: Forbidden (no access to this gateway)
229
346
* *404*: Model not found (model not enabled in gateway)
230
347
* *429*: Rate limit exceeded (too many requests)
@@ -280,11 +397,11 @@ Compare responses, latency, and cost to determine the best model for your use ca
0 commit comments