MCPcopy Index your code
hub / github.com/coder/coder / aiGatewayProviderAuthForUser

Method aiGatewayProviderAuthForUser

coderd/x/chatd/model_routing_aibridge.go:221–253  ·  view source on GitHub ↗
(
	ctx context.Context,
	ownerID uuid.UUID,
	provider database.AIProvider,
	format aiGatewayRequestFormat,
)

Source from the content-addressed store, hash-verified

219}
220
221func (p *Server) aiGatewayProviderAuthForUser(
222 ctx context.Context,
223 ownerID uuid.UUID,
224 provider database.AIProvider,
225 format aiGatewayRequestFormat,
226) (aiGatewayProviderAuth, error) {
227 if !p.allowBYOK {
228 return aiGatewayProviderAuth{}, nil
229 }
230 userKey, err := p.db.GetUserAIProviderKeyByProviderID(ctx, database.GetUserAIProviderKeyByProviderIDParams{
231 UserID: ownerID,
232 AIProviderID: provider.ID,
233 })
234 if err != nil {
235 if xerrors.Is(err, sql.ErrNoRows) {
236 return aiGatewayProviderAuth{}, nil
237 }
238 return aiGatewayProviderAuth{}, xerrors.Errorf("get user AI provider key: %w", err)
239 }
240 apiKey := strings.TrimSpace(userKey.APIKey)
241 if apiKey == "" {
242 return aiGatewayProviderAuth{}, nil
243 }
244
245 headers := map[string]string{}
246 switch format {
247 case aiGatewayRequestFormatAnthropic:
248 headers["X-Api-Key"] = apiKey
249 default:
250 headers["Authorization"] = "Bearer " + apiKey
251 }
252 return aiGatewayProviderAuth{Headers: headers}, nil
253}
254
255func (p *Server) resolveAIGatewayRoute(
256 ctx context.Context,

Callers 2

resolveAIGatewayRouteMethod · 0.95

Calls 3

IsMethod · 0.45
ErrorfMethod · 0.45

Tested by 1