Skip to content

Commit a805bb9

Browse files
committed
Support customize completion api url via custom providers.
1 parent 69d41ef commit a805bb9

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Fix anthropic api for custom providers.
6+
- Support customize completion api url via custom providers.
7+
58
## 0.26.0
69

710
- Support manual approval for specific tools. #44

docs/configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ It's possible to configure ECA to be aware of custom LLM providers if they follo
113113
"my-company": {
114114
"api": "openai",
115115
"urlEnv": "MY_COMPANY_API_URL", // or "url": "https://litellm.my-company.com",
116+
// "completionUrlRelativePath": "/v1/responses", // only if default is not enough,
116117
"keyEnv": "MY_COMPANY_API_KEY", // or "key": "123",
117-
"models": ["gpt-4.1", "deepseek-r1"],
118+
"models": ["gpt-5", "deepseek-r1"],
118119
"defaultModel": "deepseek-r1"
119120
}
120121
}
@@ -219,6 +220,7 @@ interface Config {
219220
defaultModel?: string;
220221
url?: string;
221222
urlEnv?: string;
223+
completionUrlRelativePath?: string;
222224
key?: string;
223225
keyEnv?: string;
224226
}};

src/eca/llm_api.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@
169169
"anthropic" llm-providers.anthropic/completion!
170170
(on-error-wrapper {:message (format "Unknown custom model %s for provider %s" (:api provider-config) provider)}))
171171
url (or (:url provider-config) (config/get-env (:urlEnv provider-config)))
172-
key (or (:key provider-config) (config/get-env (:keyEnv provider-config)))]
172+
key (or (:key provider-config) (config/get-env (:keyEnv provider-config)))
173+
url-relative-path (:completionUrlRelativePath provider-config)]
173174
(provider-fn
174175
{:model model
175176
:instructions instructions
@@ -180,6 +181,7 @@
180181
:tools tools
181182
:extra-payload extra-payload
182183
:api-url url
184+
:url-relative-path url-relative-path
183185
:api-key key}
184186
callbacks))
185187

src/eca/llm_providers/anthropic.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
:max_uses 10
2727
:cache_control {:type "ephemeral"}})))
2828

29-
(defn ^:private base-request! [{:keys [rid body api-url api-key content-block* on-error on-response]}]
30-
(let [url (str api-url messages-path)
29+
(defn ^:private base-request! [{:keys [rid body api-url api-key url-relative-path content-block* on-error on-response]}]
30+
(let [url (str api-url (or url-relative-path messages-path))
3131
reason-id (str (random-uuid))]
3232
(llm-util/log-request logger-tag rid url body)
3333
(http/post
@@ -96,7 +96,7 @@
9696

9797
(defn completion!
9898
[{:keys [model user-messages temperature instructions max-output-tokens
99-
api-url api-key reason? past-messages tools web-search extra-payload]
99+
api-url api-key url-relative-path reason? past-messages tools web-search extra-payload]
100100
:or {temperature 1.0}}
101101
{:keys [on-message-received on-error on-reason on-prepare-tool-call on-tools-called on-usage-updated]}]
102102
(let [messages (concat (normalize-messages past-messages)
@@ -175,6 +175,7 @@
175175
:body (assoc body :messages messages)
176176
:api-url api-url
177177
:api-key api-key
178+
:url-relative-path url-relative-path
178179
:content-block* (atom nil)
179180
:on-error on-error
180181
:on-response handle-response}))
@@ -191,6 +192,7 @@
191192
:body body
192193
:api-url api-url
193194
:api-key api-key
195+
:url-relative-path url-relative-path
194196
:content-block* (atom nil)
195197
:on-error on-error
196198
:on-response on-response-fn})))

src/eca/llm_providers/openai.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
(def base-url "https://api.openai.com")
1717

18-
(defn ^:private base-completion-request! [{:keys [rid body api-url api-key on-error on-response]}]
19-
(let [url (str api-url responses-path)]
18+
(defn ^:private base-completion-request! [{:keys [rid body api-url url-relative-path api-key on-error on-response]}]
19+
(let [url (str api-url (or url-relative-path responses-path))]
2020
(llm-util/log-request logger-tag rid url body)
2121
(http/post
2222
url
@@ -69,7 +69,7 @@
6969
%) c))))))
7070
past-messages))
7171

72-
(defn completion! [{:keys [model user-messages instructions reason? api-key api-url
72+
(defn completion! [{:keys [model user-messages instructions reason? api-key api-url url-relative-path
7373
max-output-tokens past-messages tools web-search extra-payload]}
7474
{:keys [on-message-received on-error on-prepare-tool-call on-tools-called on-reason on-usage-updated]}]
7575
(let [input (concat (normalize-messages past-messages)
@@ -168,6 +168,7 @@
168168
{:rid (llm-util/gen-rid)
169169
:body (assoc body :input input)
170170
:api-url api-url
171+
:url-relative-path url-relative-path
171172
:api-key api-key
172173
:on-error on-error
173174
:on-response handle-response})
@@ -186,6 +187,7 @@
186187
{:rid (llm-util/gen-rid)
187188
:body body
188189
:api-url api-url
190+
:url-relative-path url-relative-path
189191
:api-key api-key
190192
:on-error on-error
191193
:on-response on-response-fn})))

0 commit comments

Comments
 (0)