Call the Responses API from Python with the openai library's responses.create.
POST /v1/responses speaks the Responses shape, so the openai library's client.responses drives it unchanged — point it at https://opendunes.com/v1 with your API key.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://opendunes.com/v1",
api_key=os.environ["OPENDUNES_API_KEY"],
)
response = client.responses.create(
model="openai/gpt-5.1",
instructions="You answer Souk customers in French.",
input="Quels sont vos horaires le vendredi ?",
)
print(response.output_text)
print(response.usage) # input and output tokens, and cost in DAstream = client.responses.create(
model="openai/gpt-5.1",
input="Write a haiku about the Sahara.",
stream=True,
)
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)The usage, with cost in DA, rides the closing response.completed event.
The API is stateless: nothing is kept between requests, and previous_response_id is refused with a 400. Send the conversation again each turn — the earlier output items can go straight back into input:
history = [{"role": "user", "content": "What is the capital of Algeria?"}]
first = client.responses.create(model="openai/gpt-5.1", input=history)
history += first.output
history.append({"role": "user", "content": "What language is spoken there?"})
second = client.responses.create(model="openai/gpt-5.1", input=history)
print(second.output_text)An error comes back as a failed response in the Responses shape; the library raises APIStatusError with its status_code. See Errors.