OpenAI
The direct provider for OpenAI models. The app sends each request straight to OpenAI and streams the reply; tools execute locally.
Construct it
let agent = try runtime.makeAgent(
provider: .openAI(apiKey: key, model: "gpt-4o"),
role: AgentRole(staticPersona: "You are a precise video-editing assistant.")
)
Hold the provider directly when you need it:
let provider = OpenAIProvider(apiKey: key, model: "gpt-4o")
model defaults to gpt-4o and is a plain string — any model OpenAI
offers works without a framework update. baseURL: points the provider at
an OpenAI-compatible proxy.
What it supports
| Capability | Value |
|---|---|
| execution | app-driven (the session runs the loop) |
| context window | 128,000 tokens |
| vision | yes |
| tool choice | yes, native |
| structured output | yes, native |
Structured turns (get data, not prose) ride OpenAI's strict JSON-schema response format. The schema root must be an object — a non-object root is rejected before any request is sent.
The full flag-by-flag table lives in the capability matrix.
Keep the key out of shipped apps
.openAI(apiKey:) sends the key from the device — fine for prototypes,
extractable from any shipped binary. For production,
name an agent profile instead of a key.