bailey Responses API
bailey is a ready-to-deploy Health AI Assistant. In addition to the bailey Chat Completions API, bailey implements the newer OpenAI Responses API.
Any code that can talk to the OpenAI Responses API should be able to talk to the bailey API without any change.
Important Notes
- The Responses API is stateful. Instead of resending the full conversation history on every call (as with Chat Completions), pass
previous_response_idto continue a prior turn — bailey resolves the prior context for you. - To make a response resumable, set
store: trueon the request. Only responses created withstore: truecan later be referenced viaprevious_response_id. - Stored response context is held in memory per-instance and expires after 1 hour. Do not rely on
previous_response_idfor long-lived conversation state — persist your own transcript on the client if you need it beyond that window. - Ownership of a stored response is tied to the authenticated user who created it — a
previous_response_idcreated by one user cannot be resolved by another. - We recommend rendering streaming responses in your UI for the best user experience.
- Uses the same token as other SDKs.
- Available on the public internet — no backend routing needed.
Endpoint
POST https://api.prod.icanbwell.com/bailey/v1/responses
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The model to use for generating the response. |
input | string or array | Yes | The input text, or a list of input items, to generate a response for. |
stream | boolean | No | Stream the response via Server-Sent Events. Defaults to false. |
instructions | string | No | System instructions to apply for this response (max 2000 characters). |
previous_response_id | string | No | ID of a prior response (created with store: true) to continue from. |
store | boolean | No | If true, persists this response so it can be referenced later via previous_response_id. Defaults to false. |
temperature | number | No | Sampling temperature, between 0 and 2. |
top_p | number | No | Nucleus sampling probability, between 0 and 1. |
max_output_tokens | integer | No | Maximum number of tokens to generate. |
tools | array | No | Tool definitions available to the model, including MCP tool servers. |
tool_choice | string or object | No | Controls which tool, if any, the model calls. |
parallel_tool_calls | boolean | No | Whether the model may call multiple tools in parallel. |
metadata | object | No | Arbitrary key-value metadata to associate with the response. |
user | string | No | A stable identifier for the end user, for abuse monitoring. |
Integration Options
Option 1: OpenAI PyPI Package
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
api_key="your-client-key", # pragma: allowlist secret
base_url="https://api.prod.icanbwell.com/bailey/v1",
default_headers={
"Authorization": "Bearer your-user-token",
},
)
async def stream_response() -> None:
stream = await client.responses.create(
model="Bailey AI",
input="What is healthcare?",
stream=True,
)
async for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
asyncio.run(stream_response())To continue the conversation, capture the id from the completed response and pass it back as previous_response_id on the next call (the original response must have been created with store=True):
first = await client.responses.create(
model="Bailey AI",
input="What is healthcare?",
store=True,
)
second = await client.responses.create(
model="Bailey AI",
input="Can you say more about that?",
previous_response_id=first.id,
store=True,
)Option 2: Python Direct HTTP Calls
import json
from collections.abc import AsyncGenerator
import httpx
async def stream_responses_api(
*,
user_token: str,
client_key: str,
prompt: str,
model: str,
base_url: str = "https://api.prod.icanbwell.com/bailey/v1",
) -> AsyncGenerator[str, None]:
headers = {
"Authorization": f"Bearer USER_TOKEN",
"Content-Type": "application/json",
"api-key": client_key,
}
payload = {
"model": model,
"input": prompt,
"stream": True,
}
async with httpx.AsyncClient() as client:
async with client.stream(
"POST", f"{base_url}/responses", headers=headers, json=payload
) as response:
async for line in response.aiter_lines():
if not line.startswith("data: "):
continue
data = line[len("data: ") :]
if data == "[DONE]":
break
event = json.loads(data)
if event.get("type") == "response.output_text.delta":
yield event.get("delta", "")Option 3: cURL Command
curl -X POST https://api.prod.icanbwell.com/bailey/v1/responses \
-H "Authorization: Bearer your-user-token" \
-H "api-key: your-client-key" \
-H "Content-Type: application/json" \
-d '{
"model": "Bailey AI",
"input": "What is healthcare?",
"stream": true
}'Option 4: JavaScript with OpenAI npm Package
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-client-key",
baseURL: "https://api.prod.icanbwell.com/bailey/v1",
defaultHeaders: {
Authorization: "Bearer your-user-token",
},
});
async function streamResponse() {
const stream = await client.responses.create({
model: "Bailey AI",
input: "What is healthcare?",
stream: true,
});
for await (const event of stream) {
if (event.type === "response.output_text.delta") {
process.stdout.write(event.delta);
}
}
}
streamResponse();Option 5: JavaScript Native Fetch
async function streamResponsesApi({ userToken, clientKey, prompt, model, baseUrl }) {
const response = await fetch(`${baseUrl}/responses`, {
method: "POST",
headers: {
Authorization: `Bearer $USERTOKEN`,
"api-key": clientKey,
"Content-Type": "application/json",
},
body: JSON.stringify({
model,
input: prompt,
stream: true,
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split("\n");
buffer = lines.pop() ?? "";
for (const line of lines) {
if (!line.startsWith("data: ")) continue;
const data = line.slice(6);
if (data === "[DONE]") return;
const event = JSON.parse(data);
if (event.type === "response.output_text.delta") {
process.stdout.write(event.delta);
}
}
}
}Non-Streaming Response Shape
{
"id": "resp_a1b2c3d4e5f60708",
"object": "response",
"created_at": 1732820000,
"model": "Bailey AI",
"status": "completed",
"output": [
{
"id": "0",
"type": "message",
"role": "assistant",
"status": "completed",
"content": [
{
"type": "output_text",
"text": "Healthcare is...",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 12,
"output_tokens": 48,
"total_tokens": 60
}
}Updated 9 days ago
Did this page help you?
