@@ -1723,7 +1723,35 @@ func (a *App) testModelsAPI(apiUrl, apiKey, transformer string) (int, error) {
17231723 if resp .StatusCode != http .StatusOK {
17241724 return resp .StatusCode , fmt .Errorf ("HTTP %d" , resp .StatusCode )
17251725 }
1726- return resp .StatusCode , nil
1726+
1727+ // Check if models list is not empty
1728+ body , err := io .ReadAll (resp .Body )
1729+ if err != nil {
1730+ return resp .StatusCode , fmt .Errorf ("failed to read response" )
1731+ }
1732+
1733+ var result map [string ]interface {}
1734+ if err := json .Unmarshal (body , & result ); err != nil {
1735+ return resp .StatusCode , fmt .Errorf ("failed to parse response" )
1736+ }
1737+
1738+ // OpenAI/Claude format: {"data": [...]}
1739+ if data , ok := result ["data" ].([]interface {}); ok {
1740+ if len (data ) == 0 {
1741+ return resp .StatusCode , fmt .Errorf ("no models found" )
1742+ }
1743+ return resp .StatusCode , nil
1744+ }
1745+
1746+ // Gemini format: {"models": [...]}
1747+ if models , ok := result ["models" ].([]interface {}); ok {
1748+ if len (models ) == 0 {
1749+ return resp .StatusCode , fmt .Errorf ("no models found" )
1750+ }
1751+ return resp .StatusCode , nil
1752+ }
1753+
1754+ return resp .StatusCode , fmt .Errorf ("unexpected response format" )
17271755}
17281756
17291757func (a * App ) testTokenCountAPI (apiUrl , apiKey string ) (int , error ) {
@@ -1756,6 +1784,22 @@ func (a *App) testTokenCountAPI(apiUrl, apiKey string) (int, error) {
17561784 if resp .StatusCode != http .StatusOK {
17571785 return resp .StatusCode , fmt .Errorf ("HTTP %d" , resp .StatusCode )
17581786 }
1787+
1788+ // Verify response contains input_tokens
1789+ respBody , err := io .ReadAll (resp .Body )
1790+ if err != nil {
1791+ return resp .StatusCode , fmt .Errorf ("failed to read response" )
1792+ }
1793+
1794+ var result map [string ]interface {}
1795+ if err := json .Unmarshal (respBody , & result ); err != nil {
1796+ return resp .StatusCode , fmt .Errorf ("failed to parse response" )
1797+ }
1798+
1799+ if _ , ok := result ["input_tokens" ]; ! ok {
1800+ return resp .StatusCode , fmt .Errorf ("invalid response: no input_tokens" )
1801+ }
1802+
17591803 return resp .StatusCode , nil
17601804}
17611805
@@ -1779,6 +1823,18 @@ func (a *App) testBillingAPI(apiUrl, apiKey string) (int, error) {
17791823 if resp .StatusCode != http .StatusOK {
17801824 return resp .StatusCode , fmt .Errorf ("HTTP %d" , resp .StatusCode )
17811825 }
1826+
1827+ // Verify response is valid JSON (billing API returns grant info)
1828+ respBody , err := io .ReadAll (resp .Body )
1829+ if err != nil {
1830+ return resp .StatusCode , fmt .Errorf ("failed to read response" )
1831+ }
1832+
1833+ var result map [string ]interface {}
1834+ if err := json .Unmarshal (respBody , & result ); err != nil {
1835+ return resp .StatusCode , fmt .Errorf ("failed to parse response" )
1836+ }
1837+
17821838 return resp .StatusCode , nil
17831839}
17841840
0 commit comments