From 127128db19866ae3fda5adb7daffce50d0007ddb Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 May 2024 14:26:12 +0200 Subject: [PATCH] OpenAI: rate limiting logging --- app/src/main/java/eu/faircode/email/OpenAI.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/OpenAI.java b/app/src/main/java/eu/faircode/email/OpenAI.java index e9c3af24b2..eab61bd67c 100644 --- a/app/src/main/java/eu/faircode/email/OpenAI.java +++ b/app/src/main/java/eu/faircode/email/OpenAI.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Objects; public class OpenAI { @@ -239,6 +240,18 @@ public class OpenAI { String response = Helper.readStream(connection.getInputStream()); Log.i("OpenAI response=" + response); + try { + // https://platform.openai.com/docs/guides/rate-limits/rate-limits-in-headers + for (Map.Entry> entries : connection.getHeaderFields().entrySet()) { + String key = entries.getKey(); + if (key != null && key.startsWith("x-ratelimit")) + for (String value : entries.getValue()) + Log.i("OpenAI", key + "=" + value); + } + } catch (Throwable ex) { + Log.w(ex); + } + return new JSONObject(response); } finally { connection.disconnect();