Run a Delphi in your harness
Use the OpenAI Responses API with your own tools, streaming, and Pydantic AI.
Connect your harness to a Delphi through the OpenAI Responses API. Delphi supplies the owner's identity and freshly retrieved knowledge. Your harness supplies the task, executes function tools, and keeps the conversation history.
Connect
Base URL
https://api.delphi.ai/v4/agents
Model
delphi
API key
A Delphi key with generate:text scope
Transport
OpenAI Responses API
Create a key in API Keys. The key selects its owner's Delphi automatically. No slug is needed. Calls use PUBLIC knowledge and anonymous visitor context; caller-supplied identity or access-tier headers cannot unlock private knowledge or visitor memory.
The OpenAI client's Authorization: Bearer header works directly. You can also use x-api-key; if you send both, they must contain the same key. Keep your key on your server and set it as the DELPHI_API_KEY environment variable.
Model discovery is available at GET /v4/agents/models. Choose the Responses transport in your harness; Chat Completions and Anthropic Messages are not supported on this base URL.
Make a request
These examples were verified with OpenAI 2.40.0 and Pydantic AI 1.105.0:
python -m pip install "openai==2.40.0" "pydantic-ai-slim[openai]==1.105.0"Save each Python example in its own file and run it with DELPHI_API_KEY set.
import os
from openai import OpenAI
with OpenAI(
api_key=os.environ["DELPHI_API_KEY"],
base_url="https://api.delphi.ai/v4/agents",
timeout=180,
max_retries=0,
) as client:
response = client.responses.create(
model="delphi",
input="How would you decide which project to pursue next?",
store=False,
)
if response.status != "completed":
raise RuntimeError(f"Response ended with {response.status}")
print(response.output_text)Use tools and continue the conversation
This Pydantic AI example runs a local inventory function, requests a structured recommendation, then asks a follow-up using the complete history. Replace the inventory fixture with your own service call. The fixture's prices come from your tool; the recommendation also draws on the Delphi's knowledge.
WithJsonSchema keeps the price fields numeric in the submitted JSON schema while Python validates them as Decimal. The inventory fixture supplies seven units at 13.25 each, for a total of 92.75. The follow-up reuses that result.
If you manage the tool loop yourself:
Send function definitions in
toolsand your conversation ininput.Append the returned
response.outputitems to your history. Execute eachfunction_callin your harness, then append afunction_call_outputwith its originalcall_idand the tool's result inoutput.Send the full history again with the same tools and instructions. Include results for every call in a parallel batch before adding another message.
Preserve function-call items and argument strings; replacing them with prose loses the tool contract. Delphi rebuilds its grounding on every request, including tool continuations.
Stream text
Set stream=True to receive Responses events. Text chunks are provisional until the stream reaches response.completed.
Streaming also carries function-call events. With Pydantic AI, use agent.run_stream(...); call await result.get_output() before using a structured result, and retain result.all_messages() for the next turn.
Supported options and limits
History: text messages, function calls, and function results. Use
input, notmessages. Setstore:falseand supply complete history on every call. No Delphi threads or visitor memories are created.Tools: caller-defined functions, parallel calls, and
tool_choicevaluesauto,none,required, or a named function. Names must be unique;build_contextis reserved. JSON schema references must be local fragments.Output: text, JSON objects, or JSON schemas through
text.format. Incomplete responses can contain unfinished JSON; check status before parsing. Truncated function calls must not be executed.Generation:
max_output_tokens,temperature, andtop_pare supported. The output-token budget includes the internal context call and any structured output repair. Disconnecting cancels generation.Unsupported:
previous_response_id, saved conversations, hosted tools, images, audio, and background execution. Unsupported options return400.
Your key's request limits and the owner's daily generation budget apply. Each Responses request, including a tool continuation or retry, counts as a generation attempt. The generation budget is shared across the owner's keys. Model discovery does not consume a generation attempt.
Handle failures
HTTP errors use {"error":{"message":"...","type":"...","code":"..."}}.
400
Unsupported options, malformed tool history, or conflicting auth headers.
401
Missing or invalid Delphi API key.
403
API access, generate:text scope, or a required tool blocked by a safety finding.
404
The key owner's Delphi is missing or inactive.
429
Request limits or daily generation budget; respect Retry-After when present.
5xx
A service could not complete the request.
After streaming starts, failures may arrive as response.failed; token limits or content filtering can produce response.incomplete. Check the terminal event as well as the HTTP status.
The examples disable automatic HTTP retries. Retrying starts a new generation; responses are not stored or replayed by idempotency key. Your harness controls whether to repeat a tool action that may already have completed.
Last updated