MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / updateChannelOpenAISBBalance

Function updateChannelOpenAISBBalance

controller/channel-billing.go:172–192  ·  view source on GitHub ↗
(channel *model.Channel)

Source from the content-addressed store, hash-verified

170}
171
172func updateChannelOpenAISBBalance(channel *model.Channel) (float64, error) {
173 url := fmt.Sprintf("https://api.openai-sb.com/sb-api/user/status?api_key=%s", channel.Key)
174 body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
175 if err != nil {
176 return 0, err
177 }
178 response := OpenAISBUsageResponse{}
179 err = json.Unmarshal(body, &response)
180 if err != nil {
181 return 0, err
182 }
183 if response.Data == nil {
184 return 0, errors.New(response.Msg)
185 }
186 balance, err := strconv.ParseFloat(response.Data.Credit, 64)
187 if err != nil {
188 return 0, err
189 }
190 channel.UpdateBalance(balance)
191 return balance, nil
192}
193
194func updateChannelAIProxyBalance(channel *model.Channel) (float64, error) {
195 url := "https://aiproxy.io/api/report/getUserOverview"

Callers

nothing calls this directly

Calls 3

GetResponseBodyFunction · 0.85
GetAuthHeaderFunction · 0.85
UpdateBalanceMethod · 0.80

Tested by

no test coverage detected