OpenAI 모델 - Amazon Bedrock

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

OpenAI 모델

OpenAI는 다음과 같은 개방형 모델을 제공합니다.

  • gpt-oss-20b - 짧은 지연 시간과 로컬 또는 특수 사용 사례에 최적화된 소형 모델입니다.

  • gpt-oss-120b - 프로덕션 및 범용 또는 높은 이유의 사용 사례에 최적화된 더 큰 모델입니다.

다음 표에는 모델에 대한 정보가 요약되어 있습니다.

정보 gpt-oss-20b gpt-oss-120b
릴리스 날짜 2025년 8월 5일 2025년 8월 5일
모델 ID openai.gpt-oss-20b-1:0 openai.gpt-oss-120b-1:0
제품 ID N/A N/A
지원되는 입력 양식 텍스트 텍스트
지원되는 출력 양식 텍스트 텍스트
컨텍스트 창 128,000 128,000

OpenAI 모델은 다음 기능을 지원합니다.

OpenAI 요청 본문

요청 본문의 파라미터와 해당 설명에 대한 자세한 내용은 OpenAI 설명서의 채팅 완료 생성을 참조하세요.

다음과 같은 방법으로 요청 본문 필드를 사용합니다.

  • InvokeModel 또는 OpenAI Chat Completions 요청에서 요청 본문에 필드를 포함합니다.

  • Converse 요청에서 다음을 수행합니다.

    • 다음과 messages 같이를 매핑합니다.

      • 역할이 인 각 메시지에 대해 system 배열에 content SystemContentBlockdeveloper추가합니다.

      • 역할이 user 또는 인 각 메시지에 대해 content 필드의 content ContentBlock에를 assistant추가하고 messages 배열의 메시지 role role 필드에를 지정합니다.

    • 다음 필드의 값을 inferenceConfig 객체의 해당 필드에 매핑합니다.

      OpenAI field Converse 필드
      max_completion_토큰 maxTokens
      중단 stopSequences
      temperature temperature
      top_p topP
    • additionalModelRequestFields 객체에 다른 필드를 포함합니다.

요청 본문 구성 시 고려 사항
  • OpenAI 모델은 텍스트 입력 및 텍스트 출력만 지원합니다.

  • model 필드의 값은 헤더의 값과 일치해야 합니다. 이 필드를 생략하여 헤더와 동일한 값으로 자동으로 채워지도록 할 수 있습니다.

  • stream 필드의 값은 사용하는 API 작업과 일치해야 합니다. 이 필드를 생략하여 올바른 값으로 자동으로 채워지도록 할 수 있습니다.

    • InvokeModel을 사용하는 경우 stream 값은 여야 합니다false.

OpenAI 응답 본문

OpenAI 모델의 응답 본문은에서 반환한 채팅 완료 객체를 따릅니다OpenAI. 응답 필드에 대한 자세한 내용은 OpenAI 설명서의 채팅 완료 객체를 참조하세요.

참고

InvokeModel를 사용하는 경우 <reasoning> 태그로 묶인 모델 추론이 응답의 텍스트 콘텐츠보다 우선합니다.

OpenAI 모델 사용 예

이 섹션에서는 OpenAI 모델 사용 방법의 몇 가지 예를 제공합니다.

다음 예제를 시도하기 전에 사전 조건을 충족했는지 확인하세요.

  • 인증 - 자격 AWS 증명 또는 Amazon Bedrock API 키로 인증할 수 있습니다.

    자격 AWS 증명을 설정하거나 Amazon Bedrock API 키를 생성하여 요청을 인증합니다.

    참고

    OpenAI 채팅 완료 API를 사용하는 경우 Amazon Bedrock API 키로만 인증할 수 있습니다.

  • 엔드포인트 - Amazon Bedrock 런타임 엔드포인트 및 할당량에 사용할 AWS 리전에 해당하는 엔드포인트를 찾습니다. https://docs.aws.amazon.com/general/latest/gr/bedrock.html#br-rt AWS SDK를 사용하는 경우 클라이언트를 설정할 때 전체 엔드포인트가 아닌 리전 코드만 지정하면 될 수 있습니다. 예제에 사용된 모델에서 지원하는 리전과 연결된 엔드포인트를 사용해야 합니다.

  • 모델 액세스 - OpenAI 모델에 대한 액세스를 요청합니다. 자세한 내용은 Amazon Bedrock 파운데이션 모델에 대한 액세스 추가 또는 제거 단원을 참조하십시오.

  • (이 예제에서 SDK를 사용하는 경우) SDK 설치 - 설치 후 기본 자격 증명과 기본 AWS 리전을 설정합니다. 기본 자격 증명 또는 리전을 설정하지 않은 경우 관련 코드 예제에서 명시적으로 지정해야 합니다. 표준화된 자격 증명 공급자에 대한 자세한 내용은 AWS SDKs.

    참고

    OpenAI SDK를 사용하는 경우 Amazon Bedrock API 키로만 인증할 수 있으며 Amazon Bedrock 엔드포인트를 명시적으로 설정해야 합니다.

보려는 예제의 섹션을 확장합니다.

채팅 완료 API OpenAI 생성 사용 예제를 보려면 원하는 방법의 탭을 선택한 다음 다음 단계를 따릅니다.

OpenAI SDK (Python)

다음 Python 스크립트는 OpenAI Python SDK를 사용하여 채팅 완료 생성 API를 호출합니다.

from openai import OpenAI client = OpenAI( base_url="https://bedrock-runtime.us-west-2.amazonaws.com/openai/v1", api_key="$AWS_BEARER_TOKEN_BEDROCK" ) completion = client.chat.completions.create( model="openai.gpt-oss-20b-1:0", messages=[ { "role": "developer", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello!" } ] ) print(completion.choices[0].message)
HTTP request using curl

터미널에서 다음 명령을 실행하여 curl을 사용하여 채팅 완료 생성 API를 호출할 수 있습니다.

curl -X POST https://bedrock-runtime.us-west-2.amazonaws.com/openai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $AWS_BEARER_TOKEN_BEDROCK" \ -d '{ "model": "openai.gpt-oss-20b-1:0", "messages": [ { "role": "developer", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello!" } ] }'

원하는 방법의 탭을 선택한 다음 다음 단계를 따릅니다.

Python
import boto3 import json # Initialize the Bedrock Runtime client client = boto3.client('bedrock-runtime') # Model ID model_id = 'openai.gpt-oss-20b-1:0' # Create the request body native_request = { "model": model_id, # You can omit this field "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "assistant", "content": "Hello! How can I help you today?" }, { "role": "user", "content": "What is the weather like today?" } ], "max_completion_tokens": 150, "temperature": 0.7, "top_p": 0.9, "stream": False # You can omit this field } # Make the InvokeModel request response = client.invoke_model( modelId=model_id, body=json.dumps(native_request) ) # Parse and print the message for each choice in the chat completion response_body = json.loads(response['body'].read().decode('utf-8')) for choice in response_body['choices']: print(choice['message']['content'])

통합 Converse API를 사용하는 경우 채팅 완료 필드 OpenAI 생성을 Converse 요청 본문의 해당 필드에 매핑해야 합니다.

예를 들어 다음 채팅 완료 요청 본문을 해당 Converse 요청 본문과 비교합니다.

Create chat completion request body
{ "model": "openai.gpt-oss-20b-1:0", "messages": [ { "role": "developer", "content": "You are a helpful assistant." }, { "role": "assistant", "content": "Hello! How can I help you today?" }, { "role": "user", "content": "What is the weather like today?" } ], "max_completion_tokens": 150, "temperature": 0.7 }
Converse request body
{ "messages": [ { "role": "user", "content": [ { "text": "Hello! How can I help you today?" } ] }, { "role": "user", "content": [ { "text": "What is the weather like today?" } ] } ], "system": [ { "text": "You are a helpful assistant." } ], "inferenceConfig": { "maxTokens": 150, "temperature": 0.7 } }

원하는 방법의 탭을 선택한 다음 다음 단계를 따릅니다.

Python
# Use the Conversation API to send a text message to Anthropic Claude. import boto3 from botocore.exceptions import ClientError # Initialize the Bedrock Runtime client client = boto3.client("bedrock-runtime") # Set the model ID model_id = "openai.gpt-oss-20b-1:0" # Set up messages and system message messages = [ { "role": "assistant", "content": [ { "text": "Hello! How can I help you today?" } ] }, { "role": "user", "content": [ { "text": "What is the weather like today?" } ] } ] system = [ { "text": "You are a helpful assistant." } ] try: # Send the message to the model, using a basic inference configuration. response = client.converse( modelId=model_id, messages=messages, system=system, inferenceConfig={ "maxTokens": 150, "temperature": 0.7, "topP": 0.9 }, ) # Extract and print the response text. for content_block in response["output"]["message"]["content"]: print(content_block) except (ClientError, Exception) as e: print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}") exit(1)

모델 호출 요청의 헤더에서 가드레일 추적을 활성화할지 여부를 지정하여 모델 호출을 실행할 때 가드레일을 적용합니다.

원하는 방법의 탭을 선택한 다음 다음 단계를 따릅니다.

Python
import boto3 from botocore.exceptions import ClientError import json # Initiate the Amazon Bedrock Runtime client bedrock_runtime = boto3.client("bedrock-runtime") # Model ID model_id = "openai.gpt-oss-20b-1:0" # Replace with actual values from your guardrail guardrail_id = "GR12345" guardrail_version = "DRAFT" # Create the request body native_request = { "model": model_id, # You can omit this field "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "assistant", "content": "Hello! How can I help you today?" }, { "role": "user", "content": "What is the weather like today?" } ], "max_completion_tokens": 150, "temperature": 0.7, "top_p": 0.9, "stream": False # You can omit this field } try: response = bedrock_runtime.invoke_model( modelId=model_id, body=json.dumps(native_request), guardrailIdentifier=guardrail_id, guardrailVersion=guardrail_version, trace='ENABLED', ) response_body = json.loads(response.get('body').read()) print("Received response from InvokeModel API (Request Id: {})".format(response['ResponseMetadata']['RequestId'])) print(json.dumps(response_body, indent=2)) except ClientError as err: print("RequestId = " + err.response['ResponseMetadata']['RequestId']) raise err

OpenAI 채팅이 완료된 가드레일을 사용하는 예를 보려면 원하는 방법의 탭을 선택한 다음 다음 단계를 따릅니다.

OpenAI SDK (Python)
import openai from openai import OpenAIError # Endpoint for Amazon Bedrock Runtime bedrock_endpoint = "https://bedrock-runtime.us-west-2.amazonaws.com/openai/v1" # Model ID model_id = "openai.gpt-oss-20b-1:0" # Replace with actual values bedrock_api_key = "$AWS_BEARER_TOKEN_BEDROCK" guardrail_id = "GR12345" guardrail_version = "DRAFT" client = openai.OpenAI( api_key=bedrock_api_key, base_url=bedrock_endpoint, ) try: response = client.chat.completions.create( model=model_id, # Specify guardrail information in the header extra_headers={ "X-Amzn-Bedrock-GuardrailIdentifier": guardrail_id, "X-Amzn-Bedrock-GuardrailVersion": guardrail_version, "X-Amzn-Bedrock-Trace": "ENABLED", }, # Additional guardrail information can be specified in the body extra_body={ "amazon-bedrock-guardrailConfig": { "tagSuffix": "xyz" # Used for input tagging } }, messages=[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "assistant", "content": "Hello! How can I help you today?" }, { "role": "user", "content": "What is the weather like today?" } ] ) request_id = response._request_id print(f"Request ID: {request_id}") print(response) except OpenAIError as e: print(f"An error occurred: {e}") if hasattr(e, 'response') and e.response is not None: request_id = e.response.headers.get("x-request-id") print(f"Request ID: {request_id}")
OpenAI SDK (Java)
import com.openai.client.OpenAIClient; import com.openai.client.okhttp.OpenAIOkHttpClient; import com.openai.core.http.HttpResponseFor; import com.openai.models.chat.completions.ChatCompletion; import com.openai.models.chat.completions.ChatCompletionCreateParams; // Endpoint for Amazon Bedrock Runtime String bedrockEndpoint = "http://bedrock-runtime.us-west-2.amazonaws.com/openai/v1" // Model ID String modelId = "openai.gpt-oss-20b-1:0" // Replace with actual values String bedrockApiKey = "$AWS_BEARER_TOKEN_BEDROCK" String guardrailId = "GR12345" String guardrailVersion = "DRAFT" OpenAIClient client = OpenAIOkHttpClient.builder() .apiKey(bedrockApiKey) .baseUrl(bedrockEndpoint) .build() ChatCompletionCreateParams request = ChatCompletionCreateParams.builder() .addUserMessage("What is the temperature in Seattle?") .model(modelId) // Specify additional headers for the guardrail .putAdditionalHeader("X-Amzn-Bedrock-GuardrailIdentifier", guardrailId) .putAdditionalHeader("X-Amzn-Bedrock-GuardrailVersion", guardrailVersion) // Specify additional body parameters for the guardrail .putAdditionalBodyProperty( "amazon-bedrock-guardrailConfig", JsonValue.from(Map.of("tagSuffix", JsonValue.of("xyz"))) // Allows input tagging ) .build(); HttpResponseFor<ChatCompletion> rawChatCompletionResponse = client.chat().completions().withRawResponse().create(request); final ChatCompletion chatCompletion = rawChatCompletionResponse.parse(); System.out.println(chatCompletion);

배치 추론을 사용하면 여러 프롬프트와 비동기적으로 모델 추론을 실행할 수 있습니다. OpenAI 모델을 사용하여 배치 추론을 실행하려면 다음을 수행합니다.

  1. JSONL 파일을 생성하고 각각 새 줄로 구분된 최소 수의 JSON 객체로 채웁니다. 각 modelInput 객체는 OpenAI 채팅 완료 생성 요청 본문의 형식을 준수해야 합니다. 다음은에 대한 요청 본문이 포함된 JSONL 파일의 처음 두 줄의 예를 보여줍니다OpenAI.

    { "recordId": "RECORD1", "modelInput": { "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Can you generate a question with a factual answer?" } ], "max_completion_tokens": 1000 } } { "recordId": "RECORD2", "modelInput": { "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "What is the weather like today?" } ], "max_completion_tokens": 1000 } } ...
    참고

    필드를 생략하면 배치 추론 서비스가 헤더를 기반으로 필드를 삽입하므로 model 필드는 선택 사항입니다.

    JSONL 파일이에 설명된 배치 추론 할당량을 준수하는지 확인합니다추론 데이터의 형식 지정 및 업로드.

  2. Amazon S3 버킷에 이미지 파일을 업로드합니다.

  3. 필드에 지정된 이전 단계의 S3 버킷과 inputDataConfig 필드에 지정된 OpenAI 모델을 사용하여 Amazon Bedrock 컨트롤 플레인 엔드포인트CreateModelInvocationJob 요청을 보냅니다modelId.

end-to-end 코드 예제는 섹션을 참조하세요배치 추론을 위한 코드 예제. 를 OpenAI 모델에 적합한 구성으로 바꿉니다.