Skip to content

Replace an Assistants API Call With the Responses API

The Assistants API is no longer available, so replace the old Assistant–Thread–Run sequence with one Responses API request for a simple text task. The example below uses the current Python SDK, instructions, input, store=False, a concrete acceptance check, and a local mock test that does not make a paid live request.

Prerequisites and the legacy-to-current mapping

Install the official Python SDK and set OPENAI_API_KEY in your environment. The OpenAI quickstart uses OpenAI() and client.responses.create(...); the SDK reads the key automatically from the environment. Developer quickstart

Legacy Assistants conceptCurrent Responses conceptWhat changes in code
AssistantPrompt or request-level instructionsPut the former behavior rules in instructions, or manage a dashboard prompt when appropriate.
ThreadConversation or explicit input itemsSend the current user input directly, or attach it to a Conversation.
RunResponseReplace run creation and polling with client.responses.create(...).
Run stepItemInspect typed output items when you need tool calls, refusals, or other events.

For this small replacement, do not create a Prompt or Conversation object. Put the old Assistant’s behavior in instructions and send the user’s request through input. The migration guide documents Prompts and Conversations for more persistent configuration and history, but it also notes that reusable prompt objects are being deprecated, so review that lifecycle before making them central to a long-lived design.

The sample uses gpt-5.6-terra, whose current model page lists Responses support and pricing of $2 per million input tokens and $12 per million output tokens. A real execution can incur usage charges; the example below is not a report of a live call.

Complete worked example with input and output

Install the dependencies:

python -m pip install openai pytest

Save this as responses_example.py:

MODEL = "gpt-5.6-terra"

INSTRUCTIONS = """
You classify customer support messages.
Return exactly three lines:
Category: <one of billing, technical, account>
Priority: <one of low, normal, high>
Reason: <one short sentence>
Do not add Markdown or extra commentary.
""".strip()

USER_INPUT = (
    "I was charged twice for the same monthly subscription, "
    "and I need the duplicate charge reversed."
)

def classify(client, text=USER_INPUT):
    return client.responses.create(
        model=MODEL,
        instructions=INSTRUCTIONS,
        input=text,
        store=False,
    )


def main():
    from openai import OpenAI
    print(classify(OpenAI()).output_text)


if __name__ == "__main__":
    main()

instructions replaces the system-like behavior that was previously held by the Assistant configuration. input replaces the new message added to a Thread, and output_text is the convenient SDK property for the generated text. The store=False control makes the example explicit about response storage; it does not make the request free.

Example input: The concrete request is I was charged twice for the same monthly subscription, and I need the duplicate charge reversed.

Expected output: The following is invented illustrative output, not output from a live API call.

Category: billing
Priority: high
Reason: The customer reports a duplicate subscription charge.

The model may vary the wording of the reason while following the requested format. If your application needs machine-stable fields rather than formatted text, migrate the prompt to the Responses API’s structured-output configuration and validate the returned data against your schema.

Acceptance checks

The acceptance target is a response with three non-empty lines, the exact labels Category, Priority, and Reason, and a billing classification for this fixture. You can test the request shape locally by replacing the network client with a fake object.

Save this as test_responses_example.py:

from dataclasses import dataclass
from typing import Any
from responses_example import MODEL, INSTRUCTIONS, USER_INPUT, classify


@dataclass
class FakeResponse:
    output_text: str
    id: str = "resp_local_mock"


class FakeResponses:
    def __init__(self) -> None:
        self.calls: list[dict[str, Any]] = []

    def create(self, **kwargs: Any) -> FakeResponse:
        self.calls.append(kwargs)
        return FakeResponse(
            output_text=(
                "Category: billing\n"
                "Priority: high\n"
                "Reason: The customer reports a duplicate charge."
            )
        )


class FakeClient:
    def __init__(self) -> None:
        self.responses = FakeResponses()


def test_original_request_shape_and_output():
    client = FakeClient()
    response = classify(client)
    assert client.responses.calls == [{
        "model": MODEL, "instructions": INSTRUCTIONS,
        "input": USER_INPUT, "store": False,
    }]
    lines = response.output_text.splitlines()
    assert len(lines) == 3
    assert [line.split(":", 1)[0] for line in lines] == ["Category", "Priority", "Reason"]
    assert lines[0] == "Category: billing"


def test_custom_input_reaches_the_original_function():
    client = FakeClient()
    classify(client, "I cannot sign in to my account.")
    assert client.responses.calls[0]["input"] == "I cannot sign in to my account."

Verify the result: Run pytest -q test_responses_example.py and require both tests to pass without an API key, network access, or an OpenAI() instance. These tests import and call the same function as the live example, and check that the migration uses responses.create, sends the intended input, disables storage explicitly, and reads response.output_text.

Specific failures and recovery

A common failure is leaving the old call path in place:

client.beta.threads.runs.create(
    thread_id=thread_id,
    assistant_id=assistant_id,
)

After the sunset, this cannot be recovered by changing only the Assistant ID. Replace the entire sequence with client.responses.create(...). If old conversation history matters, use messages stored by your application; the migration guide states that retrieving thread messages through the retired Assistants API no longer works.

A second failure is model_not_found or an invalid model error. Confirm that the model identifier is available to the project, then replace gpt-5.6-terra with a currently available model from the OpenAI model catalog. Do not treat the illustrative model name as a permanent compatibility guarantee.

This method is unsuitable when the application depends on audio input or output, a specialized realtime workflow, or a complex tool loop that has not been migrated. It is also incomplete for a multi-turn product unless you choose a state strategy: use a Conversation, pass previous_response_id, or store and resend the required items yourself. The conversation state documentation explains those alternatives and their retention implications.

Frequently Asked Questions (FAQ)

Q1) Do I need to create a Prompt to replace every Assistant?

No. For a small request, copy the former Assistant behavior into the request’s instructions field. A dashboard Prompt can be useful for centrally managed configuration, but it is not required for a single Responses API call. Check the current Prompt lifecycle before building new infrastructure around reusable prompt objects.

Q2) Does store=False prevent all data retention?

No. It controls response application storage, but it does not override organization-level retention, abuse-monitoring, or tool-specific policies. Responses are stored for 30 days by default, while store=False disables that response storage behavior. Review the current data controls documentation for your organization’s exact requirements.

Q3) Can I reuse an old Thread after the Assistants sunset?

Not through the retired Assistants endpoints. Recover the history from your own database or exported records, convert user messages to input items, and create a new Conversation if persistent state is needed. Do not assume that old Thread IDs can be passed directly to the Responses API.

Leave a comment