Skip to content

OpenAI API

The OpenAI API provides a simple interface to state-of-the-art AI models for text generation, natural language processing, computer vision, and more.


OpenAIServer allows you to expose your agents and LLMs to external systems that support the Chat completion or Responses API.

Key benefits

  • Fast setup with minimal configuration
  • Support for Chat Completion API and Responses API
  • Register multiple agents and LLMs on a single server
  • Custom server settings
from beeai_framework.adapters.openai.serve.server import OpenAIAPIType, OpenAIServer, OpenAIServerConfig
from beeai_framework.agents.requirement import RequirementAgent
from beeai_framework.backend import ChatModel
from beeai_framework.memory import UnconstrainedMemory
from beeai_framework.tools.weather import OpenMeteoTool
def main() -> None:
llm = ChatModel.from_name("ollama:granite4:micro")
agent = RequirementAgent(
llm=llm,
tools=[OpenMeteoTool()],
memory=UnconstrainedMemory(),
)
server = OpenAIServer(
config=OpenAIServerConfig(
port=9998,
api=OpenAIAPIType.RESPONSES,
)
)
server.register(agent, name="agent")
server.register(llm)
server.serve()
if __name__ == "__main__":
main()

Agent execution (Python)

Pass execution=AgentExecutionConfig(...) to server.register() to configure max_iterations, total_max_retries, and max_retries_per_step for the built-in RequirementAgent, ToolCallingAgent, and ReActAgent. These options apply to every request served by that registration. Omitted fields and fields set to None retain the agent’s own defaults. The configuration is copied during registration, and non-empty execution configuration is rejected for other runnable types.

You can easily call the exposed entities via cURL.

Terminal window
curl --location 'http://127.0.0.1:9998/responses' \
--header 'Content-Type: application/json' \
--data '{
"model": "agent",
"conversation": "123",
"stream": false,
"input": "Hello, how are you?"
}'