Flex processing

Flex processing

Flex processing는 더 느린 응답 시간과 때때로 발생하는 리소스 불가능(unavailability)을 대가로 Responses 또는 Chat Completions 요청에 더 낮은 비용을 제공합니다. 모델 평가, 데이터 보강(enrichment), 비동기 워크로드 같은 비프로덕션 또는 낮은 우선순위 작업에 적합합니다.

토큰은 Batch API 요금으로 가격이 책정되며, 프롬프트 캐싱으로 추가 할인을 받을 수 있습니다.

Flex processing은 제한된 모델 가용성으로 베타 상태입니다. 지원되는 모델은 가격 페이지에 나와 있습니다.

출처: 문서

본문

API 사용

Flex processing을 사용하려면 API 요청에서 service_tier 매개변수를 flex로 설정하세요:

Flex processing 예시

import OpenAI from "openai";
const client = new OpenAI({
  timeout: 15 * 1000 * 60, // Increase default timeout to 15 minutes
});

const response = await client.responses.create(
  {
    model: "gpt-6-astra",
    instructions: "List and describe all the metaphors used in this book.",
    input: "<very long text of book here>",
    service_tier: "flex",
  },
  { timeout: 15 * 1000 * 60 }
);

console.log(response.output_text);
from openai import OpenAI

client = OpenAI(
    # increase default timeout to 15 minutes (from 10 minutes)
    timeout=900.0
)

# you can override the max timeout per request as well
response = client.with_options(timeout=900.0).responses.create(
    model="gpt-6-astra",
    instructions="List and describe all the metaphors used in this book.",
    input="<very long text of book here>",
    service_tier="flex",
)

print(response.output_text)
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/openai/openai-go/v3"
	"github.com/openai/openai-go/v3/option"
	"github.com/openai/openai-go/v3/responses"
)

func main() {
	client := openai.NewClient(option.WithRequestTimeout(15 * time.Minute))
	response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
		Model:        "gpt-6-astra",
		Instructions: openai.String("List and describe all the metaphors used in this book."),
		Input:        responses.ResponseNewParamsInputUnion{OfString: openai.String("<very long text of book here>")},
		ServiceTier:  responses.ResponseNewParamsServiceTierFlex,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(response.OutputText())
}
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import java.time.Duration;

client = client.withOptions(options -> options.timeout(Duration.ofMinutes(15)));

ResponseCreateParams params =
    ResponseCreateParams.builder()
        .model("gpt-6-astra")
        .input("<very long text of book here>")
        .instructions("List and describe all the metaphors used in this book.")
        .serviceTier(ResponseCreateParams.ServiceTier.FLEX)
        .build();

client.responses().create(params).output().stream()
    .flatMap(item -> item.message().stream())
    .flatMap(message -> message.content().stream())
    .flatMap(content -> content.outputText().stream())
    .forEach(text -> System.out.println(text.text()));
using System.ClientModel;
using OpenAI.Responses;
#pragma warning disable OPENAI001

string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClientOptions clientOptions = new() { NetworkTimeout = TimeSpan.FromMinutes(15) };
ResponsesClient client = new(new ApiKeyCredential(key), clientOptions);

CreateResponseOptions options = new()
{
    Model = "gpt-6-astra",
    Instructions = "List and describe all the metaphors used in this book.",
    ServiceTier = ResponseServiceTier.Flex,
};
options.InputItems.Add(ResponseItem.CreateUserMessageItem("<very long text of book here>"));

using CancellationTokenSource timeout = new(TimeSpan.FromMinutes(15));
ResponseResult response = await client.CreateResponseAsync(options, timeout.Token);
Console.WriteLine(response.GetOutputText());
require "openai"

client = OpenAI::Client.new(timeout: 900.0)

response = client.responses.create(
  model: "gpt-6-astra",
  service_tier: :flex,
  instructions: "List and describe all the metaphors used in this book.",
  input: "<very long text of book here>"
)

puts(response.output_text)
curl https://api.openai.com/v1/responses \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-astra",
    "instructions": "List and describe all the metaphors used in this book.",
    "input": "<very long text of book here>",
    "service_tier": "flex"
  }'

API 요청 타임아웃

Flex processing은 처리 속도가 느리므로 요청 타임아웃이 발생할 가능성이 더 높습니다. 타임아웃 처리에 대한 몇 가지 고려 사항은 다음과 같습니다:

  • 기본 타임아웃: 공식 OpenAI SDK로 API 요청을 할 때 기본 타임아웃은 10분입니다. 긴 프롬프트나 복잡한 작업에서는 이 타임아웃을 늘려야 할 수 있습니다.
  • 타임아웃 구성: 각 SDK는 이 타임아웃을 늘리는 매개변수를 제공합니다. Python과 JavaScript SDK에서는 위 코드 샘플처럼 이것이 timeout입니다.
  • 자동 재시도: OpenAI SDK는 408 Request Timeout 오류 코드가 발생하는 요청을 예외를 던지기 전에 자동으로 두 번 재시도합니다.

리소스 불가능 오류

Flex processing은 때때로 요청을 처리할 충분한 리소스가 없어 429 Resource Unavailable 오류 코드가 발생할 수 있습니다. 이 경우에는 요금이 청구되지 않습니다.

리소스 불가능 오류 처리 전략을 고려하세요:

  • 지수 백오프로 요청 재시도: 지수 백오프(exponential backoff)를 구현하는 것은 지연을 허용할 수 있는 워크로드에 적합하며 비용을 최소화하는 데 목적이 있습니다. 용량이 더 확보되면 요청이 결국 완료될 수 있기 때문입니다. 구현 세부 사항은 이 쿡북을 참고하세요.

  • 표준 처리를 사용해 요청 재시도: 리소스 불가능 오류가 발생하면, 성공적인 완료를 보장하는 것이 더 높은 비용을 감수할 만큼 가치가 있는 사용 사례라면 표준 처리를 사용한 재시도 전략을 구현하세요. 이렇게 하려면 재시도한 요청에서 service_tier를 auto로 설정하거나, service_tier 매개변수를 제거해 프로젝트의 기본 모드를 사용하세요.

더 알아보기 (Learn more)