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

Method aiProvidersList

coderd/ai_providers.go:51–95  ·  view source on GitHub ↗

@Summary List AI providers @ID list-ai-providers @Security CoderSessionToken @Produce json @Tags AI Providers @Success 200 {array} codersdk.AIProvider @Router /api/v2/ai/providers [get]

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

49// @Success 200 {array} codersdk.AIProvider
50// @Router /api/v2/ai/providers [get]
51func (api *API) aiProvidersList(rw http.ResponseWriter, r *http.Request) {
52 ctx := r.Context()
53
54 rows, err := api.Database.GetAIProviders(ctx, database.GetAIProvidersParams{
55 IncludeDisabled: true,
56 })
57 if dbauthz.IsNotAuthorizedError(err) {
58 api.Logger.Error(ctx, "list AI providers", slog.Error(err))
59 httpapi.Forbidden(rw)
60 return
61 }
62 if err != nil {
63 api.Logger.Error(ctx, "list AI providers", slog.Error(err))
64 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
65 Message: "Internal error listing AI providers.",
66 Detail: err.Error(),
67 })
68 return
69 }
70
71 keysByProvider, err := loadAIProviderKeysByProvider(ctx, api.Database)
72 if err != nil {
73 api.Logger.Error(ctx, "list AI provider keys", slog.Error(err))
74 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
75 Message: "Internal error loading AI provider keys.",
76 Detail: err.Error(),
77 })
78 return
79 }
80
81 out := make([]codersdk.AIProvider, 0, len(rows))
82 for _, row := range rows {
83 sdk, err := db2sdk.AIProvider(row, keysByProvider[row.ID])
84 if err != nil {
85 api.Logger.Error(ctx, "convert AI provider", slog.F("provider_id", row.ID), slog.Error(err))
86 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
87 Message: "Internal error converting AI provider.",
88 Detail: err.Error(),
89 })
90 return
91 }
92 out = append(out, sdk)
93 }
94 httpapi.Write(ctx, rw, http.StatusOK, out)
95}
96
97// @Summary Get an AI provider
98// @ID get-an-ai-provider

Callers

nothing calls this directly

Calls 8

IsNotAuthorizedErrorFunction · 0.92
ForbiddenFunction · 0.92
WriteFunction · 0.92
AIProviderFunction · 0.92
ContextMethod · 0.65
GetAIProvidersMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected