Skip to content

response API added - #165

Open
rafasashi wants to merge 1 commit into
orhanerday:mainfrom
rafasashi:main
Open

response API added#165
rafasashi wants to merge 1 commit into
orhanerday:mainfrom
rafasashi:main

Conversation

@rafasashi

Copy link
Copy Markdown

I have added support for the v1/response API

  • background => true enables background/asynchronous processing.
  • GET /responses/{id} checks the status.
  • POST /responses/{id}/cancel cancels it.
  • stream => true streams output immediately and is not background processing.
$payload = [
    'model' => 'gpt-4.1-mini',
    'input' => 'Process this task in the background.',
    'background' => true,
];
$response = $this->post(
    Url::responsesUrl(),
    $payload
);

The API will return a response ID. You can poll it using:

$responseId = $response['id'];

$status = $this->get(
    Url::responseUrl($responseId)
);

Example polling loop:

do {
    sleep(2);

    $response = $this->get(
        Url::responseUrl($responseId)
    );

    $status = $response['status'];
} while (in_array($status, ['queued', 'in_progress'], true));

if ($status === 'completed') {
    // Process the completed response.
} else {
    // Handle failed or cancelled response.
}

To cancel a background response:

$this->post(
    Url::cancelResponseUrl($responseId),
    []
);

Streaming usage:


$payload = [
    'model' => 'gpt-4.1-mini',
    'input' => 'Stream this response.',
    'stream' => true,
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant