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_id to continue a prior turn — bailey resolves the prior context for you.
  • To make a response resumable, set store: true on the request. Only responses created with store: true can later be referenced via previous_response_id.
  • Stored response context is held in memory per-instance and expires after 1 hour. Do not rely on previous_response_id for 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_id created 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

ParameterTypeRequiredDescription
modelstringYesThe model to use for generating the response.
inputstring or arrayYesThe input text, or a list of input items, to generate a response for.
streambooleanNoStream the response via Server-Sent Events. Defaults to false.
instructionsstringNoSystem instructions to apply for this response (max 2000 characters).
previous_response_idstringNoID of a prior response (created with store: true) to continue from.
storebooleanNoIf true, persists this response so it can be referenced later via previous_response_id. Defaults to false.
temperaturenumberNoSampling temperature, between 0 and 2.
top_pnumberNoNucleus sampling probability, between 0 and 1.
max_output_tokensintegerNoMaximum number of tokens to generate.
toolsarrayNoTool definitions available to the model, including MCP tool servers.
tool_choicestring or objectNoControls which tool, if any, the model calls.
parallel_tool_callsbooleanNoWhether the model may call multiple tools in parallel.
metadataobjectNoArbitrary key-value metadata to associate with the response.
userstringNoA 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
  }
}


Did this page help you?