Responses API
Use the OpenAI Responses API for multi-turn, agentic workflows with built-in tool calling.
Last updated
from openai import OpenAI
client = OpenAI(
base_url="https://api.parasail.io/v1",
api_key="<PARASAIL_API_KEY>"
)
response = client.responses.create(
model="parasail-kimi-k25-elicit",
store=False,
input="Explain the difference between TCP and UDP in two sentences."
)
print(response.output_text)curl -s https://api.parasail.io/v1/responses \
-H "Authorization: Bearer $PARASAIL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "parasail-kimi-k25-elicit",
"store": false,
"input": "Explain the difference between TCP and UDP in two sentences."
}'from openai import OpenAI
client = OpenAI(
base_url="https://api.parasail.io/v1",
api_key="<PARASAIL_API_KEY>"
)
# Turn 1
response = client.responses.create(
model="parasail-kimi-k25-elicit",
store=False,
input=[
{"role": "user", "content": "I'm planning a trip to Tokyo. What should I see on day 1?"}
]
)
turn1_text = response.output_text
print("Turn 1:", turn1_text)
# Turn 2 — pass the full history
response = client.responses.create(
model="parasail-kimi-k25-elicit",
store=False,
input=[
{"role": "user", "content": "I'm planning a trip to Tokyo. What should I see on day 1?"},
{"role": "assistant", "content": turn1_text},
{"role": "user", "content": "What about day 2? Suggest different areas."}
]
)
print("Turn 2:", response.output_text)tools = [
{
"type": "function",
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"default": "celsius"
}
},
"required": ["city"]
}
}
]from openai import OpenAI
import json
client = OpenAI(
base_url="https://api.parasail.io/v1",
api_key="<PARASAIL_API_KEY>"
)
tools = [...] # as defined above
def handle_tool_call(name, arguments):
"""Your application logic — call real APIs, databases, etc."""
args = json.loads(arguments)
if name == "get_weather":
return json.dumps({"city": args["city"], "temperature": 22, "condition": "sunny"})
return json.dumps({"error": "unknown function"})
# Initial request
response = client.responses.create(
model="parasail-kimi-k25-elicit",
store=False,
tools=tools,
input=[{"role": "user", "content": "What's the weather in Tokyo?"}]
)
# Agentic loop — keep going until the model stops calling tools
while response.output:
tool_calls = [item for item in response.output if item.type == "function_call"]
if not tool_calls:
break # Model produced a final text response
# Build input for next turn: previous output + tool results
next_input = list(response.output)
for tool_call in tool_calls:
result = handle_tool_call(tool_call.name, tool_call.arguments)
next_input.append({
"type": "function_call_output",
"call_id": tool_call.call_id,
"output": result
})
response = client.responses.create(
model="parasail-kimi-k25-elicit",
store=False,
tools=tools,
input=next_input
)
# Print final response
print(response.output_text)curl -s https://api.parasail.io/v1/models \
-H "Authorization: Bearer $PARASAIL_API_KEY"