davsclaus opened a new pull request, #30620:
URL: https://github.com/apache/camel/pull/30620

   Fixes CAMEL-27402 and CAMEL-27403, two camel-openai tickets from the new 
openai-chat-action Kamelet (apache/camel-kamelets#3365), one commit each.
   
   ## CAMEL-27402: work without an API key (local servers such as Ollama)
   
   Without an `apiKey` (and no `OPENAI_API_KEY`, `openai.api.key` or 
`oauthProfile`), the SDK refused to build the client with "At least one 
credential source must be specified". So a route to a local server that checks 
no key had to set a dummy key.
   
   - The client is now built with an internal placeholder key, 
`builder.apiKey(...)`, and its header is removed with 
`builder.removeHeaders("Authorization")`. The SDK then treats the requests as 
authenticated and sends them without an `Authorization` header, so the 
placeholder is never sent or logged.
   - Why not something cleaner, from the openai-java 4.78.0 bytecode:
     - an empty `BearerTokenCredential` builds the client, but every request 
then fails with "This request requires apiKey or workloadIdentity";
     - `httpRequestAuthenticator(...)` is `ACC_SYNTHETIC` (Kotlin hides it from 
Java), so it is not a public API to rely on.
   - A server that needs a key answers 401 as before. A configured key is still 
sent as `Bearer <key>`.
   - Docs: the `apiKey` option description and the Authentication note. The 
note already claimed the key could be omitted, which was not true before this 
fix.
   
   ## CAMEL-27403: `jsonSchemaStrict`
   
   - New option `jsonSchemaStrict`, default `false`. With it off, `strict` is 
left out of the request, so requests are unchanged. When true, it sets `strict: 
true` in the JSON schema response format of:
     - `chat-completion`;
     - the Responses API (`responses`);
     - `batch` lines for `/v1/chat/completions` and `/v1/responses`.
   - The option description and a new docs section ("Strict schema") give 
OpenAI's rules: every property of each object in `required`, 
`additionalProperties: false` on every object, otherwise HTTP 400.
   - Note: the `strict(false)` mentioned in the ticket 
(`OpenAIResponsesSupport.toFunctionTool`) is the strictness of function tools, 
a different setting, and is not changed. The JSON schema text format of the 
Responses API did not set `strict` at all.
   
   ## Tests
   
   - `OpenAINoApiKeyTest` (stub HTTP server):
     - without a key, the chat completion succeeds, the request has no 
`Authorization` header, and no header contains the placeholder;
     - with a key, the header is `Bearer sk-test`.
   - `OpenAIJsonSchemaStrictTest` (stub HTTP server): chat-completion and 
responses send no `strict` by default, and `"strict":true` with the option.
   - `OpenAIBatchMockTest`: strict chat and Responses batch lines.
   - All 430 tests of camel-openai pass.
   - Generated files: the component JSON, the catalog copies (JSON and docs) 
and the endpoint DSL are updated.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to