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

Method aiProvidersGet

coderd/ai_providers.go:105–134  ·  view source on GitHub ↗

@Summary Get an AI provider @ID get-an-ai-provider @Security CoderSessionToken @Produce json @Tags AI Providers @Param idOrName path string true "Provider ID or name" @Success 200 {object} codersdk.AIProvider @Router /api/v2/ai/providers/{idOrName} [get]

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

Source from the content-addressed store, hash-verified

103// @Success 200 {object} codersdk.AIProvider
104// @Router /api/v2/ai/providers/{idOrName} [get]
105func (api *API) aiProvidersGet(rw http.ResponseWriter, r *http.Request) {
106 ctx := r.Context()
107
108 row, err := lookupAIProvider(ctx, api.Database, chi.URLParam(r, "idOrName"))
109 if err != nil {
110 writeAIProviderError(ctx, api.Logger, rw, err, "lookup AI provider", "Internal error fetching AI provider.")
111 return
112 }
113
114 keys, err := api.Database.GetAIProviderKeysByProviderID(ctx, row.ID)
115 if err != nil {
116 api.Logger.Error(ctx, "fetch AI provider keys", slog.F("provider_id", row.ID), slog.Error(err))
117 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
118 Message: "Internal error loading AI provider keys.",
119 Detail: err.Error(),
120 })
121 return
122 }
123
124 sdk, err := db2sdk.AIProvider(row, keys)
125 if err != nil {
126 api.Logger.Error(ctx, "convert AI provider", slog.F("provider_id", row.ID), slog.Error(err))
127 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
128 Message: "Internal error converting AI provider.",
129 Detail: err.Error(),
130 })
131 return
132 }
133 httpapi.Write(ctx, rw, http.StatusOK, sdk)
134}
135
136// @Summary Create an AI provider
137// @ID create-an-ai-provider

Callers

nothing calls this directly

Calls 7

WriteFunction · 0.92
AIProviderFunction · 0.92
lookupAIProviderFunction · 0.85
writeAIProviderErrorFunction · 0.85
ContextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected