SpyBara
Go Premium

Reference 2026-06-23 22:00 UTC to 2026-06-24 22:02 UTC

2 files changed +107 −110. View all changes and history on the product overview
2026
Wed 24 22:02 Tue 23 22:00 Wed 17 18:02 Tue 16 21:57 Fri 12 00:01 Wed 10 15:48 Tue 9 06:34 Fri 5 06:45 Thu 4 06:52 Tue 2 06:51

python/index.md +53 −8

Details

928 928 

929## Amazon Bedrock929## Amazon Bedrock

930 930 

931To use this library with [Amazon Bedrock's OpenAI-compatible API](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html), use the `BedrockOpenAI` class instead of the `OpenAI` class.931To use this library with [Amazon Bedrock's OpenAI-compatible API](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html), configure the standard `OpenAI` client with the Bedrock provider.

932 

933Install the optional Bedrock dependencies to use the standard AWS credential chain and SigV4 authentication:

934 

935```sh

936pip install 'openai[bedrock]'

937```

932 938 

933```py939```py

934from openai import BedrockOpenAI940from openai import OpenAI

941from openai.providers import bedrock

935 942 

936# gets the bearer token from AWS_BEARER_TOKEN_BEDROCK and the region from AWS_REGION/AWS_DEFAULT_REGION943# Uses your normal AWS credentials. You can omit region when it is

937client = BedrockOpenAI()944# configured through AWS_REGION, AWS_DEFAULT_REGION, or your AWS profile.

945client = OpenAI(

946 provider=bedrock(

947 region="us-west-2",

948 )

949)

938 950 

939response = client.responses.create(951response = client.responses.create(

940 model="openai.gpt-5.4",952 model="openai.gpt-5.4",


944print(response.output_text)956print(response.output_text)

945```957```

946 958 

947`BedrockOpenAI` configures AWS bearer auth and the Bedrock Mantle endpoint, then uses the normal SDK resources. AWS controls which endpoints and features are supported; unsupported calls surface the provider's normal HTTP errors through the SDK.959The provider configures AWS authentication and the Bedrock Mantle endpoint while retaining the normal SDK resources, retries, streaming, and error handling. AWS controls which endpoints and features are supported; unsupported calls surface the provider's normal HTTP errors through the SDK.

960 

961The default AWS credential chain supports environment credentials, shared credentials and config files, named profiles, SSO and assume-role profiles, and workload credentials such as ECS, EKS, and EC2 metadata. To select a named profile:

962 

963```py

964client = OpenAI(

965 provider=bedrock(

966 profile="my-profile",

967 )

968)

969```

970 

971You can also pass `access_key_id` and `secret_access_key`, with an optional `session_token`, or a refreshable `credential_provider` that returns botocore-compatible credentials. Explicit bearer and AWS credential options are mutually exclusive.

948 972 

949Pass `base_url` or set `AWS_BEDROCK_BASE_URL` to override the derived `https://bedrock-mantle.<region>.api.aws/openai/v1` endpoint. The legacy module client supports `openai.api_type = "amazon-bedrock"` or `OPENAI_API_TYPE=amazon-bedrock`.973Pass `base_url` to `bedrock(...)` or set `AWS_BEDROCK_BASE_URL` to override the derived `https://bedrock-mantle.<region>.api.aws/openai/v1` endpoint.

950 974 

951Set `AWS_BEARER_TOKEN_BEDROCK` to an [Amazon Bedrock API key](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html). To refresh tokens yourself, pass a provider instead of `api_key`:975SigV4 requests require replayable, fully serialized request bodies. Standard JSON requests already meet this requirement, and response streaming is unaffected. Low-level one-shot request streams must be buffered before sending, or sent with bearer authentication and retries disabled.

976 

977Bearer tokens remain available as a compatibility or manual authentication mode. Set `AWS_BEARER_TOKEN_BEDROCK` to an [Amazon Bedrock API key](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html), pass `api_key`, or provide a refresh callback:

952 978 

953```py979```py

980client = OpenAI(

981 provider=bedrock(

982 region="us-west-2",

983 token_provider=lambda: refresh_bedrock_token(),

984 )

985)

986```

987 

988Without explicit authentication, `AWS_BEARER_TOKEN_BEDROCK` takes precedence over the default AWS credential chain for backwards compatibility.

989 

990### Legacy `BedrockOpenAI` client

991 

992`BedrockOpenAI` and `AsyncBedrockOpenAI` remain available for existing applications and delegate to the same provider implementation. New applications should prefer `OpenAI(provider=bedrock(...))`.

993 

994```py

995from openai import BedrockOpenAI

996 

954client = BedrockOpenAI(997client = BedrockOpenAI(

955 aws_region="us-west-2",998 aws_region="us-west-2",

956 bedrock_token_provider=lambda: refresh_bedrock_token(),999 aws_profile="my-profile",

957)1000)

958```1001```

959 1002 

1003The legacy module client also continues to support `openai.api_type = "amazon-bedrock"` or `OPENAI_API_TYPE=amazon-bedrock`.

1004 

960## Versioning1005## Versioning

961 1006 

962This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:1007This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

typescript/index.md +54 −102

Details

49console.log(response.output_text);49console.log(response.output_text);

50```50```

51 51 

52### Multi-turn conversations

53 

54When you manage Responses API conversation history manually, preserve output items in order. Filtering

55`response.output` to messages can drop required reasoning or tool-call items and cause the next request to

56fail.

57 

58Use the SDK's `toResponseInputItems()` helper to normalize all replayable output items before adding them to

59the next request. For simple continuation, you can pass `previous_response_id` instead.

60 

61See the [manual conversation state example](examples/responses/manual-conversation-state.ts) and

62[conversation state guide](https://developers.openai.com/api/docs/guides/conversation-state).

63 

52The previous standard (supported indefinitely) for generating text is the [Chat Completions API](https://platform.openai.com/docs/api-reference/chat). You can use that API to generate text from the model with the code below.64The previous standard (supported indefinitely) for generating text is the [Chat Completions API](https://platform.openai.com/docs/api-reference/chat). You can use that API to generate text from the model with the code below.

53 65 

54```ts66```ts


195 207 

196## Streaming responses208## Streaming responses

197 209 

198We provide support for streaming responses using Server Sent Events (SSE).210We provide support for streaming responses using Server-Sent Events (SSE).

199 211 

200```ts212```ts

201import OpenAI from 'openai';213import OpenAI from 'openai';


365| >=500 | `InternalServerError` |377| >=500 | `InternalServerError` |

366| N/A | `APIConnectionError` |378| N/A | `APIConnectionError` |

367 379 

368## Request IDs

369 

370> For more information on debugging requests, see [these docs](https://platform.openai.com/docs/api-reference/debugging-requests)

371 

372All object responses in the SDK provide a `_request_id` property which is added from the `x-request-id` response header so that you can quickly log failing requests and report them back to OpenAI.

373 

374```ts

375const completion = await client.chat.completions.create({

376 messages: [{ role: 'user', content: 'Say this is a test' }],

377 model: 'gpt-5.5',

378});

379console.log(completion._request_id); // req_123

380```

381 

382You can also access the Request ID using the `.withResponse()` method:

383 

384```ts

385const { data: stream, request_id } = await openai.chat.completions

386 .create({

387 model: 'gpt-5.5',

388 messages: [{ role: 'user', content: 'Say this is a test' }],

389 stream: true,

390 })

391 .withResponse();

392```

393 

394## Realtime API

395 

396The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.

397 

398```ts

399import { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket';

400 

401const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-realtime-2' });

402 

403rt.on('response.output_text.delta', (event) => process.stdout.write(event.delta));

404```

405 

406For more information see [realtime.md](realtime.md).

407 

408## Microsoft Azure OpenAI

409 

410To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`

411class instead of the `OpenAI` class.

412 

413> [!IMPORTANT]

414> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params

415> won't always be correct.

416 

417```ts

418import { AzureOpenAI } from 'openai';

419import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

420 

421const credential = new DefaultAzureCredential();

422const scope = 'https://cognitiveservices.azure.com/.default';

423const azureADTokenProvider = getBearerTokenProvider(credential, scope);

424 

425const openai = new AzureOpenAI({ azureADTokenProvider });

426 

427const result = await openai.chat.completions.create({

428 model: 'gpt-5.5',

429 messages: [{ role: 'user', content: 'Say hello!' }],

430});

431 

432console.log(result.choices[0]!.message?.content);

433```

434 

435## Amazon Bedrock

436 

437To use this library with [Amazon Bedrock's OpenAI-compatible API](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html), use the `BedrockOpenAI` class instead of the `OpenAI` class.

438 

439```ts

440import { BedrockOpenAI } from 'openai';

441 

442// gets the bearer token from AWS_BEARER_TOKEN_BEDROCK and the region from AWS_REGION/AWS_DEFAULT_REGION

443const client = new BedrockOpenAI();

444 

445const response = await client.responses.create({

446 model: 'openai.gpt-5.4',

447 input: 'Say hello!',

448});

449 

450console.log(response.output_text);

451```

452 

453`BedrockOpenAI` configures AWS bearer auth and the Bedrock Mantle endpoint, then uses the normal SDK resources. AWS controls which endpoints and features are supported; unsupported calls surface the provider's normal HTTP errors through the SDK.

454 

455Pass `baseURL` or set `AWS_BEDROCK_BASE_URL` to override the derived `https://bedrock-mantle.<region>.api.aws/openai/v1` endpoint. For long-running apps, pass `bedrockTokenProvider` to refresh the Bedrock bearer token before each request.

456 

457Set `AWS_BEARER_TOKEN_BEDROCK` to an [Amazon Bedrock API key](https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html). To refresh tokens yourself, pass a provider instead of `apiKey`:

458 

459```ts

460const client = new BedrockOpenAI({

461 awsRegion: 'us-west-2',

462 bedrockTokenProvider: async () => refreshBedrockToken(),

463});

464```

465 

466For more information on support for Amazon Bedrock, see [bedrock.md](bedrock.md).

467 

468### Retries380### Retries

469 381 

470Certain errors will be automatically retried 2 times by default, with a short exponential backoff.382Certain errors will be automatically retried 2 times by default, with a short exponential backoff.


607 519 

608For more information on support for the Azure API, see [azure.md](azure.md).520For more information on support for the Azure API, see [azure.md](azure.md).

609 521 

522## Amazon Bedrock

523 

524To use this library with [Amazon Bedrock's OpenAI-compatible API](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html), configure the standard `OpenAI` client with the Bedrock provider:

525 

526```ts

527import OpenAI from 'openai';

528import { bedrock } from 'openai/providers/bedrock/aws';

529 

530const client = new OpenAI({

531 provider: bedrock({ region: 'us-west-2' }),

532});

533 

534const response = await client.responses.create({

535 model: 'openai.gpt-5.4',

536 input: 'Say hello!',

537});

538 

539console.log(response.output_text);

540```

541 

542Use a model that [supports the Responses API](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html). A model returned by the Models API may support a different Bedrock inference API instead.

543 

544This uses the regional `https://bedrock-mantle.<region>.api.aws/openai/v1` endpoint. The region can also come from `AWS_REGION` or `AWS_DEFAULT_REGION`, and `AWS_BEDROCK_BASE_URL` can override the endpoint.

545 

546The AWS entrypoint uses the standard AWS credential chain by default. It also accepts a named profile, static credentials, or a custom credential provider. Install its peer dependencies before importing it:

547 

548```bash

549npm install @aws-sdk/credential-provider-node @smithy/hash-node @smithy/signature-v4

550```

551 

552The AWS entrypoint uses normal static imports so bundlers and serverless packagers can trace these dependencies. If one is missing, importing `openai/providers/bedrock/aws` fails immediately with the runtime's normal module-not-found error, for example:

553 

554```text

555Cannot find module '@aws-sdk/credential-provider-node'

556```

557 

558For Bedrock API key authentication, import `bedrock` from `openai/providers/bedrock` instead. That entrypoint has no AWS dependencies and works in browser-compatible runtimes when `dangerouslyAllowBrowser` is enabled. SigV4 authentication is supported in Node.js and compatible server runtimes and requires replayable request bodies. The legacy, bearer-only `BedrockOpenAI` class remains available for compatibility.

559 

560For more information on support for Amazon Bedrock, see [bedrock.md](bedrock.md).

561 

610## Advanced Usage562## Advanced Usage

611 563 

612### Accessing raw Response data (e.g., headers)564### Accessing raw Response data (e.g., headers)


839- Vercel Edge Runtime.791- Vercel Edge Runtime.

840- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).792- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).

841- Nitro v2.6 or greater.793- Nitro v2.6 or greater.

842- Web browsers: disabled by default to avoid exposing your secret API credentials. Enable browser support by explicitly setting `dangerouslyAllowBrowser` to true'.794- Web browsers: disabled by default to avoid exposing your secret API credentials. Enable browser support by explicitly setting `dangerouslyAllowBrowser` to `true`.

843 <details>795 <details>

844 <summary>More explanation</summary>796 <summary>More explanation</summary>

845 797