Repository Public
1# Flex processing23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45Flex processing provides lower costs for [Responses](https://developers.openai.com/api/reference/resources/responses) or [Chat Completions](https://developers.openai.com/api/reference/resources/chat) requests in exchange for slower response times and occasional resource unavailability. It's ideal for non-production or lower priority tasks, such as model evaluations, data enrichment, and asynchronous workloads.67Tokens are [priced](https://developers.openai.com/api/docs/pricing) at [Batch API rates](https://developers.openai.com/api/docs/guides/batch), with additional discounts from [prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching).89Flex processing is in beta with limited model availability. Supported models10 are listed on the [pricing page](https://developers.openai.com/api/docs/pricing?latest-pricing=flex).1112## API usage1314To use Flex processing, set the `service_tier` parameter to `flex` in your API request:151617 Flex processing example1819```javascript20import OpenAI from "openai";21const client = new OpenAI({22 timeout: 15 * 1000 * 60, // Increase default timeout to 15 minutes23});2425const response = await client.responses.create(26 {27 model: "gpt-6-astra",28 instructions: "List and describe all the metaphors used in this book.",29 input: "<very long text of book here>",30 service_tier: "flex",31 },32 { timeout: 15 * 1000 * 60 }33);3435console.log(response.output_text);36```3738```python39from openai import OpenAI4041client = OpenAI(42 # increase default timeout to 15 minutes (from 10 minutes)43 timeout=900.044)4546# you can override the max timeout per request as well47response = client.with_options(timeout=900.0).responses.create(48 model="gpt-6-astra",49 instructions="List and describe all the metaphors used in this book.",50 input="<very long text of book here>",51 service_tier="flex",52)5354print(response.output_text)55```5657```go58package main5960import (61 "context"62 "fmt"63 "time"6465 "github.com/openai/openai-go/v3"66 "github.com/openai/openai-go/v3/option"67 "github.com/openai/openai-go/v3/responses"68)6970func main() {71 client := openai.NewClient(option.WithRequestTimeout(15 * time.Minute))72 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{73 Model: "gpt-6-astra",74 Instructions: openai.String("List and describe all the metaphors used in this book."),75 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("<very long text of book here>")},76 ServiceTier: responses.ResponseNewParamsServiceTierFlex,77 })78 if err != nil {79 panic(err)80 }81 fmt.Println(response.OutputText())82}83```8485```java86import com.openai.client.OpenAIClient;87import com.openai.client.okhttp.OpenAIOkHttpClient;88import com.openai.models.responses.ResponseCreateParams;89import java.time.Duration;9091client = client.withOptions(options -> options.timeout(Duration.ofMinutes(15)));9293ResponseCreateParams params =94 ResponseCreateParams.builder()95 .model("gpt-6-astra")96 .input("<very long text of book here>")97 .instructions("List and describe all the metaphors used in this book.")98 .serviceTier(ResponseCreateParams.ServiceTier.FLEX)99 .build();100101client.responses().create(params).output().stream()102 .flatMap(item -> item.message().stream())103 .flatMap(message -> message.content().stream())104 .flatMap(content -> content.outputText().stream())105 .forEach(text -> System.out.println(text.text()));106```107108```csharp109using System.ClientModel;110using OpenAI.Responses;111#pragma warning disable OPENAI001112113string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;114ResponsesClientOptions clientOptions = new() { NetworkTimeout = TimeSpan.FromMinutes(15) };115ResponsesClient client = new(new ApiKeyCredential(key), clientOptions);116117CreateResponseOptions options = new()118{119 Model = "gpt-6-astra",120 Instructions = "List and describe all the metaphors used in this book.",121 ServiceTier = ResponseServiceTier.Flex,122};123options.InputItems.Add(ResponseItem.CreateUserMessageItem("<very long text of book here>"));124125using CancellationTokenSource timeout = new(TimeSpan.FromMinutes(15));126ResponseResult response = await client.CreateResponseAsync(options, timeout.Token);127Console.WriteLine(response.GetOutputText());128```129130```ruby131require "openai"132133client = OpenAI::Client.new(timeout: 900.0)134135response = client.responses.create(136 model: "gpt-6-astra",137 service_tier: :flex,138 instructions: "List and describe all the metaphors used in this book.",139 input: "<very long text of book here>"140)141142puts(response.output_text)143```144145```bash146curl https://api.openai.com/v1/responses \147 -H "Authorization: Bearer $OPENAI_API_KEY" \148 -H "Content-Type: application/json" \149 -d '{150 "model": "gpt-6-astra",151 "instructions": "List and describe all the metaphors used in this book.",152 "input": "<very long text of book here>",153 "service_tier": "flex"154 }'155```156157158159160161#### API request timeouts162163Due to slower processing speeds with Flex processing, request timeouts are more likely. Here are some considerations for handling timeouts:164165- **Default timeout**: The default timeout is **10 minutes** when making API requests with an official OpenAI SDK. You may need to increase this timeout for lengthy prompts or complex tasks.166- **Configuring timeouts**: Each SDK will provide a parameter to increase this timeout. In the Python and JavaScript SDKs, this is `timeout` as shown in the code samples above.167- **Automatic retries**: The OpenAI SDKs automatically retry requests that result in a `408 Request Timeout` error code twice before throwing an exception.168169## Resource unavailable errors170171Flex processing may sometimes lack sufficient resources to handle your requests, resulting in a `429 Resource Unavailable` error code. **You will not be charged when this occurs.**172173Consider implementing these strategies for handling resource unavailable errors:174175- **Retry requests with exponential backoff**: Implementing exponential backoff is suitable for workloads that can tolerate delays and aims to minimize costs, as your request can eventually complete when more capacity is available. For implementation details, see [this cookbook](https://developers.openai.com/cookbook/examples/how_to_handle_rate_limits?utm_source=chatgpt.com#retrying-with-exponential-backoff).176177- **Retry requests with standard processing**: When receiving a resource unavailable error, implement a retry strategy with standard processing if occasional higher costs are worth ensuring successful completion for your use case. To do so, set `service_tier` to `auto` in the retried request, or remove the `service_tier` parameter to use the default mode for the project.