Skip to content

OpenAI

The OpenAI plugin provides access to OpenAI’s models including GPT-4o, DALL-E, and text embeddings.

<dependency>
<groupId>com.google.genkit</groupId>
<artifactId>genkit-plugin-openai</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Terminal window
export OPENAI_API_KEY=your-api-key
import com.google.genkit.plugins.openai.OpenAIPlugin;
Genkit genkit = Genkit.builder()
.plugin(OpenAIPlugin.create())
.build();
ModelResponse response = genkit.generate(
GenerateOptions.builder()
.model("openai/gpt-4o-mini")
.prompt("Tell me about AI")
.build());
  • openai/gpt-4o — Most capable model
  • openai/gpt-4o-mini — Fast and cost-effective
  • openai/gpt-4-turbo — Previous generation flagship
  • openai/o1-preview — Reasoning model
  • openai/o1-mini — Fast reasoning model
EmbedResponse response = genkit.embed(
"openai/text-embedding-3-small", documents
);
  • Text generation and streaming
  • Vision (image understanding)
  • Tool calling
  • Embeddings (text-embedding-3-small, text-embedding-3-large)
  • Image generation (DALL-E 3/2)
  • RAG support

See the openai sample.