File tree Expand file tree Collapse file tree 7 files changed +36
-27
lines changed
Expand file tree Collapse file tree 7 files changed +36
-27
lines changed Original file line number Diff line number Diff line change 33## Unreleased
44
55- Add workspaces to ` /doctor `
6+ - Improve LLM request logs to include headers.
67
78## 0.78.1
89
Original file line number Diff line number Diff line change 7070 (let [url (str api-url (or url-relative-path messages-path))
7171 reason-id (str (random-uuid ))
7272 oauth? (= :auth/oauth auth-type)
73+ headers (assoc-some
74+ {" anthropic-version" " 2023-06-01"
75+ " Content-Type" " application/json" }
76+ " x-api-key" (when-not oauth? api-key)
77+ " Authorization" (when oauth? (str " Bearer " api-key))
78+ " anthropic-beta" (when oauth? " oauth-2025-04-20" ))
7379 response* (atom nil )
7480 on-error (if on-stream
7581 on-error
7682 (fn [error-data]
7783 (llm-util/log-response logger-tag rid " response-error" body)
7884 (reset! response* error-data)))]
79- (llm-util/log-request logger-tag rid url body)
85+ (llm-util/log-request logger-tag rid url body headers )
8086 @(http/post
8187 url
82- {:headers (assoc-some
83- {" anthropic-version" " 2023-06-01"
84- " Content-Type" " application/json" }
85- " x-api-key" (when-not oauth? api-key)
86- " Authorization" (when oauth? (str " Bearer " api-key))
87- " anthropic-beta" (when oauth? " oauth-2025-04-20" ))
88+ {:headers headers
8889 :body (json/generate-string body)
8990 :throw-exceptions? false
9091 :async? true
Original file line number Diff line number Diff line change 6060 (fn [error-data]
6161 (llm-util/log-response logger-tag rid " response-error" body)
6262 (reset! response* error-data)))]
63- (llm-util/log-request logger-tag rid url body)
63+ (llm-util/log-request logger-tag rid url body {} )
6464 @(http/post
6565 url
6666 {:body (json/generate-string body)
Original file line number Diff line number Diff line change 3737 url (if oauth?
3838 codex-url
3939 (str api-url (or url-relative-path responses-path)))
40+ headers (assoc-some
41+ {" Authorization" (str " Bearer " api-key)
42+ " Content-Type" " application/json" }
43+ " chatgpt-account-id" (jtw-token->account-id api-key)
44+ " OpenAI-Beta" (when oauth? " responses=experimental" ),
45+ " Originator" (when oauth? " codex_cli_rs" )
46+ " Session-ID" (when oauth? (str (random-uuid ))))
4047 on-error (if on-stream
4148 on-error
4249 (fn [error-data]
4350 (llm-util/log-response logger-tag rid " response-error" body)
4451 {:error error-data}))]
45- (llm-util/log-request logger-tag rid url body)
52+ (llm-util/log-request logger-tag rid url body headers )
4653 @(http/post
4754 url
48- {:headers (assoc-some
49- {" Authorization" (str " Bearer " api-key)
50- " Content-Type" " application/json" }
51- " chatgpt-account-id" (jtw-token->account-id api-key)
52- " OpenAI-Beta" (when oauth? " responses=experimental" ),
53- " Originator" (when oauth? " codex_cli_rs" )
54- " Session-ID" (when oauth? (str (random-uuid ))))
55+ {:headers headers
5556 :body (json/generate-string body)
5657 :throw-exceptions? false
5758 :async? true
Original file line number Diff line number Diff line change 9494 on-error
9595 (fn [error-data]
9696 (llm-util/log-response logger-tag rid " response-error" error-data)
97- {:error error-data}))]
98- (llm-util/log-request logger-tag rid url body)
97+ {:error error-data}))
98+ headers (merge {" Authorization" (str " Bearer " api-key)
99+ " Content-Type" " application/json" }
100+ extra-headers)]
101+ (llm-util/log-request logger-tag rid url body headers)
99102 @(http/post
100103 url
101- {:headers (merge {" Authorization" (str " Bearer " api-key)
102- " Content-Type" " application/json" }
103- extra-headers)
104+ {:headers headers
104105 :body (json/generate-string body)
105106 :throw-exceptions? false
106107 :async? true
Original file line number Diff line number Diff line change 44 [clojure.string :as string]
55 [eca.config :as config]
66 [eca.logger :as logger]
7- [eca.secrets :as secrets])
7+ [eca.secrets :as secrets]
8+ [eca.shared :as shared])
89 (:import
910 [java.io BufferedReader]
1011 [java.nio.charset StandardCharsets]
6061 " "
6162 (-> result :output :contents )))
6263
63- (defn log-request [tag rid url body]
64- (logger/debug tag (format " [%s] Sending body: '%s', url: '%s'" rid body url)))
64+ (defn log-request [tag rid url body headers]
65+ (let [obfuscated-headers (-> headers
66+ (shared/update-some " Authorization" #(shared/obfuscate % {:preserve-num 8 }))
67+ (shared/update-some " x-api-key" shared/obfuscate))]
68+ (logger/debug tag (format " [%s] Sending body: '%s', headers: '%s', url: '%s'" rid body obfuscated-headers url))))
6569
6670(defn log-response [tag rid event data]
6771 (logger/debug tag (format " [%s] %s %s" rid (or event " " ) data)))
Original file line number Diff line number Diff line change 147147 " Obfuscate all but first 3 and last 3 characters of a string, minimum 5 characters.
148148 If the string is 4 characters or less, obfuscate all characters.
149149 Replace the middle part with asterisks, but always at least 5 asterisks."
150- [s]
150+ [s & {:keys [preserve-num]
151+ :or {preserve-num 3 }}]
151152 (when s
152153 (string/replace
153154 (if (<= (count s) 4 )
154155 (apply str (repeat (count s) " *" ))
155- (str (subs s 0 3 )
156+ (str (subs s 0 preserve-num )
156157 (apply str (repeat (- (count s) 4 ) " *" ))
157- (subs s (- (count s) 3 ))))
158+ (subs s (- (count s) preserve-num ))))
158159 (string/join " " (repeat (- (count s) 4 ) " *" )) " *****" )))
159160
160161(defn normalize-model-name [model]
You can’t perform that action at this time.
0 commit comments