OpenAI
Updated
Use OpenAI as the LLM in a Conversational AI Platform agent.
Preview documentation
OpenAI provides frontier models ranging from lightweight to high-capability.
Sample configuration
The following example shows how to configure OpenAI as the agent's LLM when you create or update an agent. For a complete example, see Create an agent and start a session.
OpenAI supports managed mode and BYOK. In managed mode, Agora provides access to OpenAI, and you don't need an OpenAI account. For BYOK, store your OpenAI API key in a secret set, and refer to it from the agent. For details, see Use managed mode and Use your own provider keys.
from agora_agent import Agent, OpenAI, secret_ref
# client is your configured Agora client
agent = (
Agent(client=client)
.with_stt(...) # configure your ASR vendor
.with_llm(
OpenAI(
api_key=secret_ref("support_prod", "openai"), # omit to use managed mode
base_url="https://api.openai.com/v1/chat/completions", # omit to use managed mode
model="gpt-4.1-mini",
max_history=32,
failure_message="Please hold on a second.",
system_messages=[
{"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."}
],
)
)
.with_tts(...) # configure your TTS vendor
)import { Agent, OpenAI, secretRef } from 'agora-agents';
// client is your configured Agora client
const agent = new Agent({ client })
.withStt(/* configure your ASR vendor */)
.withLlm(
new OpenAI({
apiKey: secretRef('support_prod', 'openai'), // omit to use managed mode
url: 'https://api.openai.com/v1/chat/completions', // omit to use managed mode
model: 'gpt-4.1-mini',
maxHistory: 32,
failureMessage: 'Please hold on a second.',
systemMessages: [
{ role: 'system', content: 'You are a friendly support agent for Acme. Keep your answers short.' },
],
}),
)
.withTts(/* configure your TTS vendor */);// client is your configured Agora client
maxHistory := 32
agent := agentkit.NewAgent(client).
WithStt( /* configure your ASR vendor */ ).
WithLlm(vendors.NewOpenAI(vendors.OpenAIOptions{
APIKey: agentkit.SecretRef("support_prod", "openai"), // omit to use managed mode
BaseURL: "https://api.openai.com/v1/chat/completions", // omit to use managed mode
Model: "gpt-4.1-mini",
MaxHistory: &maxHistory,
FailureMessage: "Please hold on a second.",
SystemMessages: []map[string]interface{}{
{"role": "system", "content": "You are a friendly support agent for Acme. Keep your answers short."},
},
})).
WithTts( /* configure your TTS vendor */ )-
Managed mode
Set
credential.modetomanagedin thellmblock. Agora provides access to OpenAI, and you don't need an OpenAI account."llm": { "credential": { "mode": "managed" }, "vendor": "openai", "style": "openai", "model": "gpt-4.1-mini", "max_history": 32, "failure_message": "Please hold on a second." } -
BYOK
Set
credential.modetobyokandcredential.fields.api_keyto a reference to your OpenAI API key in a secret set. In the following example, the key is stored asopenaiin thesupport_prodset:"llm": { "credential": { "mode": "byok", "fields": { "api_key": "$secrets.support_prod.openai" } }, "vendor": "openai", "style": "openai", "model": "gpt-4o-mini", "url": "https://api.openai.com/v1/chat/completions", "max_history": 32, "failure_message": "Please hold on a second." }
Set the system prompt and the greeting with the agent's instructions and greeting, not in the llm block.
Key parameters
The llm block takes the following fields. In the SDKs, the LLM class sets them from its options. In managed mode, omit the API key, the endpoint URL, and the vendor. Managed mode supports the models listed for model in Key parameters.
vendorstringSet to openai.
credentialobjectHow the agent authenticates with OpenAI. Set mode to managed, or to byok with fields.api_key set to a $secrets.<set>.<key> reference to your OpenAI API key. Create or manage your API key from OpenAI organization settings.
stylestringSet to openai.
modelstringRefer to OpenAI models for available models. For managed mode, use gpt-4o-mini, gpt-4.1-mini, gpt-5-nano, gpt-5-mini, or gpt-5.6-luna.
urlstringThe chat completions endpoint. Not needed in managed mode.
For complete llm block options, see Create an agent. For OpenAI-specific options and model capabilities, see the OpenAI API documentation.
