// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
[id="extensions-openai"]
= OpenAI
:linkattrs:
:cq-artifact-id: camel-quarkus-openai
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: OpenAI endpoint for chat completion.
:cq-deprecated: false
:cq-jvm-since: 3.32.0
:cq-native-since: 3.32.0

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##3.32.0## [.badge-key]##Native since##[.badge-supported]##3.32.0##
endif::[]

OpenAI endpoint for chat completion.

[id="extensions-openai-whats-inside"]
== What's inside

* xref:{cq-camel-components}::openai-component.adoc[OpenAI component], URI syntax: `openai:operation`

Please refer to the above link for usage and configuration details.

[id="extensions-openai-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-openai[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-openai</artifactId>
</dependency>
----
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-openai-usage"]
== Usage
[id="extensions-openai-usage-structured-output-with-output-class-in-native-mode"]
=== Structured output with output class in native mode

When using structured output with the `outputClass` option in native mode, you must ensure that the target class is registered for reflection.

This can be done with the `@RegisterForReflection` annotation or configuration property `quarkus.camel.native.reflection.include-patterns`. For example:

[source,java]
----
@RegisterForReflection
public class MyStructuredOutputClass {
    ...
}
----

[source,java]
----
public class Routes extends RouteBuilder {
    @Override
    public void configure() {
        from("direct:chat")
            .to("openai:chat-completion?outputClass=" + MyStructuredOutputClass.class.getName());
    }
}
----

[id="extensions-openai-usage-structured-output-with-json-schema-from-classpath-resource-in-native-mode"]
=== Structured output with JSON schema from classpath resource in native mode

When loading JSON schema classpath resources in native mode, you must ensure the resource is included in the native application.

For example, given a route like the following.

[source,java]
----
public class Routes extends RouteBuilder {
    @Override
    public void configure() {
        from("direct:chat")
            .to("openai:chat-completion?jsonSchema=resource:classpath:schemas/mySchema.json");
    }
}
----

Add the following to `application.properties`.

[source,properties]
----
quarkus.native.resources.includes=schemas/mySchema.json
----

Refer to the xref:user-guide/native-mode.adoc#reflection[Native mode] user guide for more information.

