@@ -1961,6 +1961,13 @@ func TestHandleListModels_ReturnsProviderOptionsWithoutPersistingLegacyMigration
19611961 "https://api.siliconflow.cn/v1" ,
19621962 )
19631963 }
1964+ if option , ok := optionsByID ["nearai" ]; ! ok {
1965+ t .Fatal ("nearai provider option missing" )
1966+ } else if option .DefaultAPIBase != "https://cloud-api.near.ai/v1" {
1967+ t .Fatalf ("nearai default_api_base = %q, want %q" , option .DefaultAPIBase , "https://cloud-api.near.ai/v1" )
1968+ } else if ! option .SupportsFetch {
1969+ t .Fatal ("nearai provider option should report supports_fetch" )
1970+ }
19641971 if option , ok := optionsByID ["bedrock" ]; ! ok {
19651972 t .Fatal ("bedrock provider option missing" )
19661973 } else if ! option .CreateAllowed {
@@ -2592,6 +2599,65 @@ func TestHandleFetchModels_SiliconFlowUsesOpenAICompatibleEndpoint(t *testing.T)
25922599 }
25932600}
25942601
2602+ func TestHandleFetchModels_NearAIUsesPublicModelListEndpoint (t * testing.T ) {
2603+ configPath , cleanup := setupOAuthTestEnv (t )
2604+ defer cleanup ()
2605+
2606+ var gotPath string
2607+ var gotAuth string
2608+ srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2609+ gotPath = r .URL .Path
2610+ gotAuth = r .Header .Get ("Authorization" )
2611+ w .Header ().Set ("Content-Type" , "application/json" )
2612+ fmt .Fprint (w , `{"models":[` +
2613+ `{"modelId":"zai-org/GLM-5.1-FP8","metadata":{"ownedBy":"nearai"}},` +
2614+ `{"modelId":"openai/gpt-oss-120b","metadata":{"ownedBy":"nearai"}},` +
2615+ `{"modelId":""}]}` )
2616+ }))
2617+ defer srv .Close ()
2618+
2619+ h := NewHandler (configPath )
2620+ mux := http .NewServeMux ()
2621+ h .RegisterRoutes (mux )
2622+
2623+ rec := httptest .NewRecorder ()
2624+ req := httptest .NewRequest (http .MethodPost , "/api/models/fetch" , bytes .NewBufferString (fmt .Sprintf (`{
2625+ "provider":"nearai",
2626+ "api_key":"nearai-key",
2627+ "api_base":"%s"
2628+ }` , srv .URL )))
2629+ req .Header .Set ("Content-Type" , "application/json" )
2630+ mux .ServeHTTP (rec , req )
2631+
2632+ if rec .Code != http .StatusOK {
2633+ t .Fatalf ("status = %d, want %d, body=%s" , rec .Code , http .StatusOK , rec .Body .String ())
2634+ }
2635+
2636+ if gotPath != "/model/list" {
2637+ t .Fatalf ("path = %q, want %q" , gotPath , "/model/list" )
2638+ }
2639+ if gotAuth != "Bearer nearai-key" {
2640+ t .Fatalf ("Authorization = %q, want %q" , gotAuth , "Bearer nearai-key" )
2641+ }
2642+
2643+ var resp struct {
2644+ Models []upstreamModel `json:"models"`
2645+ Total int `json:"total"`
2646+ }
2647+ if err := json .Unmarshal (rec .Body .Bytes (), & resp ); err != nil {
2648+ t .Fatalf ("Unmarshal() error = %v" , err )
2649+ }
2650+ if resp .Total != 2 || len (resp .Models ) != 2 {
2651+ t .Fatalf ("response = %+v, want two fetched models" , resp )
2652+ }
2653+ if resp .Models [0 ].ID != "zai-org/GLM-5.1-FP8" || resp .Models [0 ].OwnedBy != "nearai" {
2654+ t .Fatalf ("models[0] = %+v, want GLM model owned by nearai" , resp .Models [0 ])
2655+ }
2656+ if resp .Models [1 ].ID != "openai/gpt-oss-120b" || resp .Models [1 ].OwnedBy != "nearai" {
2657+ t .Fatalf ("models[1] = %+v, want GPT OSS model owned by nearai" , resp .Models [1 ])
2658+ }
2659+ }
2660+
25952661func TestHandleFetchModels_ModelIndexUsesStoredKey (t * testing.T ) {
25962662 var gotAuth string
25972663 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
0 commit comments