CAMEL-23968: Expose OpenAI SDK client timeout, retries and headers#24900
Conversation
Add requestTimeout, maxRetries and additionalHeader options to camel-openai and wire them in createClient. Includes configuration and mock integration tests.
gnodet
left a comment
There was a problem hiding this comment.
Review: CAMEL-23968 — Expose OpenAI SDK client timeout, retries and headers
Well-implemented feature with thorough tests. Clean, focused changes.
Implementation
The three new options are cleanly wired:
requestTimeout(long, default 0 → SDK 10-min default): Good semantics — 0 means "don't override", positive value setsDuration.ofMillis(...).maxRetries(int, default 2): Matches the SDK default, so explicitly setting 2 is a no-op — good consistency.additionalHeader(Map, prefixadditionalHeader.,security = "secret"): Correctly marked as secret since headers can contain API keys. Multi-value prefix is properly registered.
The configureHttpClient() extraction keeps createClient() readable.
Tests
Good coverage across 8 tests:
- Defaults validation
- URI parsing with all three options
- Timeout applied vs SDK default (0)
- Max retries with 0 and 5
- Additional headers wired to
ClientOptions - Null header value skipped
- End-to-end:
additionalHeadersAreSentOnChatCompletionRequestusesOpenAIMockto verify headers arrive on the wire — this is the strongest test in the set
Minor observations (non-blocking)
- The
clientOptions()test helper uses reflection (setAccessible(true)) to read the SDK's privateclientOptionsfield. This is pragmatic but fragile if the SDK renames the field — consider a comment noting this coupling for future maintainers. - No negative-value validation on
requestTimeout— if someone sets-1, the timeout just won't be applied (since> 0check). The SDK builder would likely handle it, but a doc note or validation could help. Very minor.
LGTM ✅
🤖 This review was generated by an AI agent (Claude Code) on behalf of gnodet. Opinions and technical assessments are AI-generated and should be validated by human reviewers.
…eout Note that clientOptions() tests depend on SDK internal field naming, and clarify that negative requestTimeout values fall back to the SDK default.
CAMEL-23968 — OpenAI SDK client optionsTwo commits on Main change (
|
| Option | Default | Behavior |
|---|---|---|
requestTimeout |
0 |
HTTP timeout in ms; > 0 → builder.timeout(...); otherwise SDK default (~10 min) |
maxRetries |
2 |
Passed to builder.maxRetries(...) |
additionalHeader.<name> |
— | Multi-value headers (e.g. Azure org/key); builder.putHeader(...) |
Wiring: OpenAIEndpoint.configureHttpClient() runs from createClient().
Files: OpenAIConfiguration.java, OpenAIEndpoint.java, new OpenAIClientConfigurationTest.java (8 tests), regenerated openai.json + endpoint configurer/uri factory.
Follow-up (789f84b)
Review feedback:
- Javadoc on test helper
clientOptions()— notes reflection on SDK private fieldclientOptions(fragile if SDK renames it) requestTimeoutdocs — negative values treated like0(SDK default)
Verification
- 102/102 tests passed in
camel-openai
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
@davsclaus could you please trigger the GitHub Action? |
Commit generated catalog, component schema, and endpoint DSL artifacts for additionalHeader, maxRetries, and requestTimeout so CI clean-tree check passes. Co-Authored-By: Cursor <cursoragent@cursor.com>
gnodet
left a comment
There was a problem hiding this comment.
Re-review after 4th commit (39df501): Generated metadata regeneration for client options — standard regeneration of catalog JSON and Endpoint DSL builder. My earlier approval stands.
Claude Code on behalf of gnodet — AI-generated review
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 11 tested, 27 compile-only — current: 9 all testedMaveniverse Scalpel detected 38 affected modules (current approach: 9).
|
CAMEL-23968.
Issue
CAMEL-23968 — expose OpenAI SDK client
requestTimeout,maxRetries, andadditionalHeader.*incamel-openai.Changes
requestTimeout(ms, default0= SDK 10 min)builder.timeout(Duration.ofMillis(...))maxRetries(default2)builder.maxRetries(...)additionalHeader.<name>(multi-value,security=secret)builder.putHeader(name, value)Applied once in
createClient()via newconfigureHttpClient()method.Tests —
OpenAIClientConfigurationTest(8 tests)00and5)ClientOptionsOpenAI-Organization,api-key)Full module:
102/102passed (mvn testoncamel-openai)Git
CAMEL-23968-openai-client-options72b2285c658