오래 걸리는 AI 작업을 요청한 뒤 결과를 어떻게 다시 확인할까

오래 걸리는 AI 작업을 요청한 뒤 결과를 어떻게 다시 확인할까

Translation
Read in English

How to retrieve results after requesting a long-running AI task

Once you hand off a lengthy task to an AI, the question becomes “when did it finish, and how do I get the result?” The OpenAI Responses API’s Background mode solves this by returning a response ID immediately after the request, then letting you poll for status using that ID later—or receive a completion notification via webhook. You don’t need to hold a connection open and wait; just fetch the result when the task is done.

When Background mode is needed

A synchronous request keeps a connection open and waits until the model responds. That’s fine for short tasks, but for things like bulk document review that can take several minutes, connections time out or users are left waiting unnecessarily. Background mode solves this problem asynchronously.

OpenAI’s official documentation summarizes the criteria for choosing a completion window into three categories. Pick the window that matches when you need the result; the 2h and 8h windows come with a token-price discount. [1], [2]

  • If you need a report generated immediately while someone is waiting: use the default window (soonest), no discount
  • If you need to analyze morning tickets before an afternoon meeting: use the 2h window, 30% discount on token pricing compared to Standard
  • If you’re reviewing documents overnight and will use them the next morning: use the 8h window, 40% discount on token pricing compared to Standard

Sending the request: background: true and saving the response ID

To use Background mode, add background: true to your POST /v1/responses request. Set model and input the same way as a normal Responses API request. The API returns a response object immediately upon accepting the request; at this point the status is either queued or in_progress.

You must save the id field from the returned response object. All subsequent status checks, result retrieval, and cancellations are performed using this ID. The official documentation example shows the pattern of saving resp.id and printing resp.status.

When using a discounted completion window (2h or 8h), also set background_options.completion_window, and explicitly set service_tier to default to select Standard processing. If left as auto, the discount only applies when the API chooses Standard. For 2h and 8h requests, set stream to false or omit it. [1]

Checking status: how to poll and when to stop

If you can’t use webhooks, repeatedly call GET /v1/responses/{id} with the response ID to check status. Keep polling while status is queued or in_progress, and stop when it changes to any other status.

The official documentation’s Python example demonstrates this pattern directly. [1]

  • queued: the API has accepted the request and has not yet started processing
  • in_progress: the model is currently processing
  • completed: finished successfully; the result can be read from output_text
  • Other statuses (failed, incomplete, cancelled): handle according to your application flow

Receiving completion notifications via webhook

Using a webhook instead of polling lets the API notify you directly when processing is complete. Register a webhook endpoint in your project and subscribe to the response.completed event. It is also a good idea to subscribe to other terminal events such as failure, incomplete, and cancelled.

When an event arrives, verify the signature and then retrieve the response using event.data.id. Because webhooks can be delivered more than once, use the webhook-id header to deduplicate. If there is lengthy follow-up work to do, have the webhook handler return 2xx quickly and hand the actual processing off to a background worker. [1]

Chaining follow-up requests: using continuation_id

Background mode truly shines in multi-step agent workflows. If the first response requested a function call, you need to execute the function and then send a follow-up request containing the result.

For a follow-up request to enter the discounted priority queue, it must retain the same model, service_tier, background, completion_window, and continuation_id as the first request, and must use the same API project. Set previous_response_id to event.data.id to continue the conversation context. If you need to resume after a response has expired, omit previous_response_id and re-supply the original input along with the saved output items in order. [1]

Example task: overnight review of unapproved clauses in contracts

The following is a hypothetical application example based on the overnight document review pattern that the official documentation uses as a direct example (this is an illustrative example derived from the documentation, not an actual implementation result).

Suppose a contract reviewer wants to find unapproved clauses in dozens of contracts every night. At 11 PM they send a request to gpt-6.1-terra with background: true, completion_window: 8h, and service_tier: default. The request includes a function tool that retrieves contract IDs, and a continuation_id uniquely chosen by the application for this run is set in background_options. The response ID is saved and the reviewer goes to sleep. In the morning, when the response.completed webhook arrives, duplicate deliveries are filtered using the webhook-id header, the result is retrieved via event.data.id, and the retrieved contract body is extracted from the function_call output. A follow-up request is sent while keeping the same model, service_tier, background, completion_window, continuation_id, and the same API project, to receive the final review result. The 8h discount (40%) applies to both requests. [1]

Conditions to verify before using Background mode

Check the following conditions before using Background mode. [1], [2]

  • Discounted completion windows are available in public beta for GPT-6.2 Astra, GPT-6.2 Sol, GPT-6.1 Terra, and GPT-6 Luna
  • 2h and 8h requests share the Rate Limit with Batch API jobs under Batch/Background Rate Limits. Input tokens are deducted at submission time
  • Background mode temporarily stores request content until processing is complete, regardless of store: false or Zero Data Retention settings. Stored data is encrypted at rest
  • If you are submitting multiple independent requests all at once, Batch API is more appropriate than Background mode
  • If you need streaming, stream: true is only available with the default window (soonest). If the connection drops, reconnect by passing the sequence_number of the last event to starting_after

Further reading

References

  1. Background mode – OpenAI API
  2. OpenAI API Changelog

Source verification standard

The official source was verified on November 19, 2026. The content may be revised after that, so please check the original source for details.

日本語で読む

時間のかかるAIタスクを依頼した後、結果をどう確認するか

AIに長いタスクを任せると、「いつ終わったのか、どうやって取得するのか」が問題になります。OpenAI Responses APIのBackground modeは、リクエスト直後にレスポンスIDを返し、そのIDを使って後から状態を照会したり、webhookで完了通知を受け取ったりすることでこの問題を解決します。接続を維持して待ち続ける必要はなく、タスクが終わったときに結果を取得すればよいのです。

Background modeが必要な状況

同期リクエストは接続を開いたままにし、モデルが応答するまで待機します。タスクが短ければ問題ありませんが、大量ドキュメントのレビューのように完了まで数分以上かかる場合は、接続タイムアウトが発生したり、ユーザーが不必要に待たされたりします。Background modeはこの問題を非同期で解決します。

OpenAIの公式ドキュメントは、完了ウィンドウ(completion window)の選択基準を次の3つにまとめています。結果が必要なタイミングに合わせてウィンドウを選べばよく、2hおよび8hウィンドウにはトークン料金の割引が適用されます。 [1], [2]

  • 誰かが待っている間にレポートをすぐ生成する必要がある場合:デフォルトウィンドウ(soonest)を使用、割引なし
  • 午前のチケットを午後の会議前に分析する必要がある場合:2hウィンドウを使用、トークン料金がStandard比30%割引
  • ドキュメントを夜間にレビューして翌朝に使用する場合:8hウィンドウを使用、トークン料金がStandard比40%割引

リクエストの送信:background: trueとレスポンスIDの保存

Background modeを使用するには、POST /v1/responses リクエストに background: true を追加します。modelとinputは通常のResponses APIリクエストと同様に設定します。APIはリクエストを受け付けた直後にレスポンスオブジェクトを返し、この時点でのstatusはqueuedまたはin_progressです。

返されたレスポンスオブジェクトから必ずidフィールドを保存してください。以降の状態確認、結果取得、キャンセルはすべてこのIDを基準に行われます。公式ドキュメントの例では、resp.idを保存してresp.statusを出力するパターンが示されています。

割引完了ウィンドウ(2hまたは8h)を使用する場合は、background_options.completion_windowも設定し、service_tierをdefaultと明示してStandard処理を選択する必要があります。autoのままにすると、APIがStandardを選択した場合にのみ割引が適用されます。2hおよび8hリクエストでは、streamをfalseに設定するか省略してください。 [1]

状態確認:ポーリングの方法と終了判定

webhookを使用できない環境では、レスポンスIDを使ってGET /v1/responses/{id}を繰り返し呼び出し、状態を確認します。statusがqueuedまたはin_progressである間はポーリングを続け、それ以外の状態に変わったらポーリングを停止します。

公式ドキュメントのPythonの例が、このパターンを直接示しています。 [1]

  • queued:APIがリクエストを受け付けたが、まだ処理を開始していない状態
  • in_progress:モデルが処理中の状態
  • completed:正常に完了、output_textから結果を読み取れる
  • その他(failed、incomplete、cancelled):アプリケーションのフローに応じて処理

webhookで完了通知を受け取る

ポーリングの代わりにwebhookを使うと、処理完了時にAPIから直接通知されます。プロジェクトにwebhookエンドポイントを登録し、response.completedイベントを購読します。失敗・未完了・キャンセルなど、処理すべき終了イベントも合わせて購読することをお勧めします。

イベントが届いたら署名を検証し、event.data.idでレスポンスを照会します。webhookは重複して配信される可能性があるため、webhook-idヘッダーで重複を除外します。長い後続処理がある場合は、webhookハンドラーが素早く2xxを返し、実際の処理はバックグラウンドワーカーに委譲します。 [1]

後続リクエストの連結:continuation_idの活用

Background modeの真価は、複数ステップにわたるエージェントワークフローで発揮されます。最初のレスポンスが関数呼び出しを要求した場合、関数を実行した後、その結果を含む後続リクエストを送信する必要があります。

後続リクエストが割引優先キューに入るには、最初のリクエストと同じmodel、service_tier、background、completion_window、continuation_idを維持し、同じAPIプロジェクトを使用する必要があります。previous_response_idをevent.data.idに設定すると、会話コンテキストが引き継がれます。レスポンスが期限切れになった後に再開する必要がある場合は、previous_response_idを省略し、元のinputと保存しておいたoutputアイテムを順番に再入力してください。 [1]

タスク例:契約書の未承認項目の夜間レビュー

以下は、公式ドキュメントが直接例として挙げているovernight document reviewパターンを基にした仮想の適用例です(実際の実装結果ではなく、ドキュメントの説明から導出した例です)。

契約レビュー担当者が毎晩数十件の契約書から未承認項目を見つけたいと仮定します。午後11時に、gpt-6.1-terraに対してbackground: true、completion_window: 8h、service_tier: defaultを設定したリクエストを送信します。契約書IDを取得する関数ツールを含め、この実行のためにアプリケーションが一意に選択したcontinuation_idをbackground_optionsに設定します。レスポンスIDを保存して就寝します。朝にresponse.completedのwebhookが届いたら、webhook-idヘッダーで重複配信を除外し、event.data.idで結果を照会して、function_call出力から照会した契約書本文を取り出します。同じmodel、service_tier、background、completion_window、continuation_id、および同じAPIプロジェクトを維持しながら後続リクエストを送信し、最終的なレビュー結果を受け取ります。2つのリクエストともに8h割引(40%)が適用されます。 [1]

Background mode使用前に確認すべき条件

Background modeを使用する前に、以下の条件を確認してください。 [1], [2]

  • 割引完了ウィンドウは、GPT-6.2 Astra、GPT-6.2 Sol、GPT-6.1 Terra、GPT-6 LunaでPublic betaとして提供されています
  • 2hおよび8hリクエストは、Batch APIジョブとBatch/Background Rate Limitを共有します。入力トークンは送信時点で差し引かれます
  • Background modeは、store: falseまたはZero Data Retentionの設定に関わらず、処理完了までリクエストの内容を一時保存します。保存データは未使用状態で暗号化されます
  • 独立したリクエストを複数件まとめて送信する場合は、Background modeではなくBatch APIが適しています
  • ストリーミングが必要な場合、stream: trueはデフォルトウィンドウ(soonest)でのみ使用できます。接続が切れた場合は、最後のイベントのsequence_numberをstarting_afterに渡して再接続します

あわせて読む

参考資料

  1. バックグラウンドモード – OpenAI API
  2. OpenAI API 変更履歴

資料確認基準

2026年11月19日に公式原文を確認しました。資料はその後修正される場合がありますので、詳細は原文をご確認ください。

AI에게 긴 작업을 맡기고 나면 '언제 끝났는지, 어떻게 가져오는지'가 문제가 됩니다. OpenAI Responses API의 Background mode는 요청 직후 응답 ID를 돌려주고, 그 ID로 나중에 상태를 조회하거나 웹훅으로 완료 알림을 받는 방식으로 이 문제를 해결합니다. 연결을 붙들고 기다릴 필요 없이, 작업이 끝났을 때 결과를 가져오면 됩니다.

Background mode – OpenAI API 공식 문서 화면

Background mode가 필요한 상황

동기 요청은 연결을 열어 두고 모델이 답할 때까지 기다립니다. 작업이 짧으면 문제없지만, 대량 문서 검토처럼 완료까지 수 분 이상 걸리는 경우 연결 타임아웃이 발생하거나 사용자가 불필요하게 대기하게 됩니다. Background mode는 이 문제를 비동기로 해결합니다.

OpenAI 공식 문서는 완료 창(completion window) 선택 기준을 다음 세 가지로 정리합니다. 결과가 필요한 시점에 맞춰 창을 고르면 되고, 2h·8h 창은 토큰 요금 할인이 적용됩니다. [1], [2]

  • 보고서를 누군가 기다리는 동안 즉시 생성해야 한다면: 기본 창(soonest) 사용, 할인 없음
  • 오전 티켓을 오후 회의 전에 분석해야 한다면: 2h 창 사용, 토큰 요금 Standard 대비 30% 할인
  • 문서를 밤새 검토하고 다음 날 아침에 쓴다면: 8h 창 사용, 토큰 요금 Standard 대비 40% 할인

요청 보내기: background: true와 응답 ID 저장

Background mode를 사용하려면 POST /v1/responses 요청에 background: true를 추가합니다. 모델과 input은 일반 Responses API 요청과 동일하게 설정합니다. API는 요청을 접수하는 즉시 응답 객체를 반환하고, 이 시점의 status는 queued 또는 in_progress입니다.

반환된 응답 객체에서 반드시 id 필드를 저장해야 합니다. 이후 상태 확인, 결과 조회, 취소 모두 이 ID를 기준으로 이루어집니다. 공식 문서 예시는 resp.id를 저장하고 resp.status를 출력하는 패턴을 보여 줍니다.

할인 완료 창(2h 또는 8h)을 쓸 때는 background_options.completion_window를 함께 설정하고, service_tier를 default로 명시해 Standard 처리를 선택해야 합니다. auto로 두면 API가 Standard를 선택할 때만 할인이 적용됩니다. 2h·8h 요청은 stream을 false로 두거나 생략해야 합니다. [1]

광고

상태 확인: 폴링 방법과 종료 판단

웹훅을 사용할 수 없는 환경이라면 응답 ID로 GET /v1/responses/{id}를 반복 호출해 상태를 확인합니다. status가 queued 또는 in_progress인 동안 계속 폴링하고, 그 외 상태로 바뀌면 폴링을 멈춥니다.

공식 문서의 Python 예시는 이 패턴을 직접 보여 줍니다. [1]

  • queued: API가 요청을 수락했고 아직 처리를 시작하지 않은 상태
  • in_progress: 모델이 처리 중인 상태
  • completed: 정상 완료, output_text에서 결과를 읽을 수 있음
  • 그 외(failed, incomplete, cancelled): 애플리케이션 흐름에 따라 처리

웹훅으로 완료 알림 받기

폴링 대신 웹훅을 쓰면 완료 시점에 API가 직접 알려 줍니다. 프로젝트에 웹훅 엔드포인트를 등록하고 response.completed 이벤트를 구독합니다. 실패·미완료·취소 등 처리할 종료 이벤트도 함께 구독하는 것이 좋습니다.

이벤트가 도착하면 서명을 검증한 뒤 event.data.id로 응답을 조회합니다. 웹훅은 중복 전달될 수 있으므로 webhook-id 헤더로 중복을 걸러냅니다. 긴 후속 작업이 있다면 웹훅 핸들러는 2xx를 빠르게 반환하고 실제 처리는 백그라운드 워커에 넘깁니다. [1]

후속 요청 연결: continuation_id 활용

Background mode의 진가는 여러 단계로 이어지는 에이전트 워크플로우에서 나옵니다. 첫 응답이 함수 호출을 요청했다면, 함수를 실행한 뒤 그 결과를 담은 후속 요청을 보내야 합니다.

후속 요청이 할인 우선순위 큐에 들어가려면 첫 요청과 같은 모델, service_tier, background, completion_window, continuation_id를 유지해야 하며, 같은 API 프로젝트를 사용해야 합니다. previous_response_id를 event.data.id로 설정하면 대화 맥락이 이어집니다. 응답이 만료된 뒤 재개해야 한다면 previous_response_id를 생략하고 원래 input과 저장해 둔 output 아이템을 순서대로 다시 넣어야 합니다. [1]

작업 예시: 계약서 미승인 항목 야간 검토

다음은 공식 문서가 직접 예시로 드는 overnight document review 패턴을 바탕으로 한 가상의 적용 예시입니다(실제 구현 결과가 아닌, 문서 설명에서 도출한 예시입니다).

계약 검토 담당자가 매일 밤 수십 건의 계약서에서 미승인 항목을 찾고 싶다고 가정합니다. 오후 11시에 gpt-6.1-terra로 background: true, completion_window: 8h, service_tier: default를 설정한 요청을 보냅니다. 계약서 ID를 받아오는 함수 도구를 포함하고, 이 실행을 위해 애플리케이션이 고유하게 선택한 continuation_id를 background_options에 설정합니다. 응답 ID를 저장한 뒤 잠자리에 듭니다. 아침에 response.completed 웹훅이 도착하면 webhook-id 헤더로 중복 전달을 걸러낸 뒤 event.data.id로 결과를 조회하고 function_call 출력에서 조회된 계약서 본문을 꺼냅니다. 같은 모델, service_tier, background, completion_window, continuation_id, 그리고 같은 API 프로젝트를 유지하며 후속 요청을 보내 최종 검토 결과를 받습니다. 두 요청 모두 8h 할인(40%)이 적용됩니다. [1]

Background mode 사용 전 확인할 조건

Background mode를 쓰기 전에 아래 조건을 먼저 확인하세요. [1], [2]

  • 할인 완료 창은 GPT-6.2 Astra, GPT-6.2 Sol, GPT-6.1 Terra, GPT-6 Luna에서 public beta로 제공됩니다
  • 2h·8h 요청은 Batch API 작업과 Batch/Background Rate Limit를 공유합니다. 입력 토큰은 제출 시점에 차감됩니다
  • Background mode는 store: false 또는 Zero Data Retention 설정과 무관하게 처리 완료까지 요청 콘텐츠를 임시 저장합니다. 저장 데이터는 미사용 상태로 암호화됩니다
  • 독립적인 요청 여러 건을 한꺼번에 제출하는 경우에는 Background mode 대신 Batch API가 적합합니다
  • 스트리밍이 필요하다면 기본 창(soonest)에서만 stream: true를 쓸 수 있습니다. 연결이 끊어지면 starting_after에 마지막 이벤트의 sequence_number를 넣어 재연결합니다

함께 읽기

참고한 자료

  1. Background mode – OpenAI API
  2. OpenAI API Changelog

자료 확인 기준

2026년 11월 19일에 공식 원문을 확인했습니다. 자료는 이후 수정될 수 있으므로 세부 내용은 원문을 확인해 주세요.


cms world에서 더 알아보기

구독을 신청하면 최신 게시물을 이메일로 받아볼 수 있습니다.

답글 남기기