(string->uri (or (getenv "CLAUDE_PROXY_UPSTREAM")
"https://api.deepseek.com/anthropic")))
- (define (ts)
- (strftime "%Y-%m-%dT%H:%M:%S%z"
- (localtime (current-time))))
-
(define (log fmt . args)
(apply format
(current-error-port)
- (string-append "[claude-proxy] "
- (ts) " " fmt) args)
+ (string-append "[claude-proxy] " fmt "~%") args)
(force-output (current-error-port)))
(define (classifier? json)
- (define sys
- (assoc-ref json "system"))
(define blocks
- (if sys
- (vector->list sys)
+ (or (and=> (assoc-ref json "system") vector->list)
'()))
(define (has? prefix)
(any (lambda (b)
(hdrs (list (list 'content-type
'application/json)
(cons 'x-api-key auth))))
- (log "~a ~a [~a]"
+ (log "~a ~a [~a~a]"
'POST path
- (if is? "classifier" "pass"))
+ (if is? "classifier" "pass")
+ (if is? ", thinking-disabled" ""))
(receive (rsp body-port)
(http-request url
#:method 'POST
(list (cons 'content-type
ct))
'())))
- (log " -> ~d~%" code)
+ (log " -> ~d" code)
(values (build-response #:code code
#:headers rhdrs)
body-port)))))
(lambda (k . a)
- (log "error: ~a~%" k)
+ (log "~a ~a error: ~a"
+ 'POST
+ (uri-path (request-uri req)) k)
(ok 502 "{\"error\":\"upstream unavailable\"}"))))
(_ (ok 405 "{\"error\":\"method not allowed\"}"))))
- (log "listening on 127.0.0.1:~d~%" port)
+ (log "listening on 127.0.0.1:~d" port)
(run-server handler
'http
`(#:port ,port