@@ -31,6 +31,8 @@ func ListModels(ctx context.Context, providerName, apiKey string, cfg config.Mod
3131 return listModelsGroq (ctx , apiKey , cfg )
3232 case "openrouter" :
3333 return listModelsOpenRouter (ctx , apiKey , cfg )
34+ case "zai" :
35+ return listModelsZAI (ctx , apiKey , cfg )
3436 default :
3537 return nil , fmt .Errorf ("unknown provider %q" , providerName )
3638 }
@@ -209,6 +211,43 @@ func listModelsOpenRouter(ctx context.Context, apiKey string, cfg config.ModelPr
209211 return listModelsOpenAICompat (ctx , apiKey , cfg , "https://openrouter.ai/api" , "openrouter" )
210212}
211213
214+ // --- Z.AI ---
215+
216+ func listModelsZAI (ctx context.Context , apiKey string , cfg config.ModelProviderConfig ) ([]AvailableModel , error ) {
217+ url := baseURL (cfg , "https://api.z.ai/api/paas/v4" ) + "/models"
218+ req , err := http .NewRequestWithContext (ctx , "GET" , url , nil )
219+ if err != nil {
220+ return nil , err
221+ }
222+ req .Header .Set ("Authorization" , "Bearer " + apiKey )
223+
224+ resp , err := http .DefaultClient .Do (req )
225+ if err != nil {
226+ return nil , err
227+ }
228+ defer resp .Body .Close ()
229+ if resp .StatusCode != http .StatusOK {
230+ return nil , fmt .Errorf ("zai list models: HTTP %d" , resp .StatusCode )
231+ }
232+
233+ var body struct {
234+ Data []struct {
235+ ID string `json:"id"`
236+ } `json:"data"`
237+ }
238+ if err := json .NewDecoder (resp .Body ).Decode (& body ); err != nil {
239+ return nil , err
240+ }
241+
242+ var models []AvailableModel
243+ for _ , m := range body .Data {
244+ if strings .Contains (m .ID , "glm" ) {
245+ models = append (models , AvailableModel {ID : m .ID , DisplayName : m .ID , Provider : "zai" })
246+ }
247+ }
248+ return models , nil
249+ }
250+
212251func listModelsOpenAICompat (ctx context.Context , apiKey string , cfg config.ModelProviderConfig , defaultBase , providerName string ) ([]AvailableModel , error ) {
213252 url := baseURL (cfg , defaultBase ) + "/v1/models"
214253 req , err := http .NewRequestWithContext (ctx , "GET" , url , nil )
0 commit comments