Skip to content

docs: add HTTP mTLS transport examples - #2029

Merged
jbeckwith-oai merged 2 commits into
mainfrom
codex/api-mtls-http
Jul 31, 2026
Merged

jbeckwith-oai merged 2 commits into
mainfrom
codex/api-mtls-http

Conversation

@jbeckwith-oai

@jbeckwith-oai jbeckwith-oai commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Documents API-key + HTTP mTLS using the SDK's existing transport hooks and adds runnable Node.js, Deno, and Bun examples. Enrollment, activation, certificate requirements, and supported endpoints are linked to the OpenAI Mutual TLS Beta Program.

This intentionally adds no new mtls client option or SDK-owned transport. mTLS remains configured on the runtime HTTP client, so applications retain runtime-native support for passphrases, proxies, custom trust stores, hardware-backed keys, and certificate rotation.

Developer API

Node.js with Undici:

import { readFile } from 'node:fs/promises';
import { Agent, fetch as undiciFetch } from 'undici';
import OpenAI from 'openai';

const dispatcher = new Agent({
  connect: {
    // Leaf certificate first, followed by required intermediates.
    cert: await readFile('/path/to/client-cert-chain.pem'),
    key: await readFile('/path/to/client-key.pem'),
    // Optional, when the transport supports encrypted keys:
    // passphrase: process.env.OPENAI_MTLS_KEY_PASSPHRASE,
  },
});

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'],
  baseURL: 'https://mtls.api.openai.com/v1',
  fetch: undiciFetch,
  fetchOptions: {
    dispatcher,
    redirect: 'manual',
  },
});

try {
  const models = await client.models.list();
} finally {
  await dispatcher.close();
}

For EU Data Residency, use https://mtls-eu.api.openai.com/v1.

The same SDK contract works with runtime-native transports:

  • Deno: version-compatible Deno.createHttpClient(...) options passed through a custom fetch;
  • Bun: native fetch(..., { tls: { cert, key } });
  • Node: Undici Agent({ connect: { cert, key } }) plus matching undici.fetch.

All runnable examples set redirect: 'manual' so a certificate-bearing transport does not automatically follow a redirect to another host.

Files

  • Adds a concise mTLS section to README.md.
  • Adds examples/mtls/node.mjs, deno.mjs, and bun.mjs.
  • Adds examples/mtls/README.md with certificate-chain setup, endpoint selection, encrypted-key guidance for Node, runtime-specific transport cleanup, and Undici's current runtime requirement.
  • Adds current Undici 8 only to the examples workspace; the SDK package gains no dependency or peer dependency.

Validation

  • ./scripts/build
  • ./node_modules/.bin/prettier --check README.md examples/mtls examples/package.json package.json pnpm-lock.yaml
  • ./node_modules/.bin/eslint .
  • ./node_modules/typescript/bin/tsc -p tsconfig.json
  • node --experimental-strip-types scripts/check-node-version-policy.ts
  • ./scripts/test --runInBand — 120 suites passed, 1 skipped; 1462 tests passed, 1 skipped
  • Real API smoke tests against an enrolled disposable mTLS project:
    • Node.js example with leaf + intermediate chain — success, 184 models returned
    • Bun example with leaf + intermediate chain — success, 184 models returned
    • Deno 1.28.0 legacy option path with an enrolled direct client certificate — success, 184 models returned
    • Deno 2.5.6 modern option path with an enrolled direct client certificate — success, 184 models returned
    • Deno 2.5.6 example with leaf + intermediate chain — success, 184 models returned
    • checked-in Node.js example with Undici 8.8.0 and an enrolled direct client certificate — success, 184 models returned
    • no-certificate control — expected 401 certificate_required

@jbeckwith-oai jbeckwith-oai changed the title feat: add first-class HTTP mTLS client certificate support docs: add HTTP mTLS transport examples Jul 29, 2026
@jbeckwith-oai
jbeckwith-oai marked this pull request as ready for review July 30, 2026 15:44
@jbeckwith-oai
jbeckwith-oai requested a review from a team as a code owner July 30, 2026 15:44
@openai-sdks

openai-sdks Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 237/237 SDK tests passed in 11.844s for Node SDK PR #2029.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 285ms
tests/chat-completions-create.test.ts ✅ Passed 334ms
tests/chat-completions-stream.test.ts ✅ Passed 291ms
tests/files-content-binary.test.ts ✅ Passed 200ms
tests/files-create-multipart.test.ts ✅ Passed 276ms
tests/files-list-pagination.test.ts ✅ Passed 205ms
tests/initialize-config.test.ts ✅ Passed 267ms
tests/instance-isolation.test.ts ✅ Passed 215ms
tests/models-list.test.ts ✅ Passed 165ms
tests/responses-background-lifecycle.test.ts ✅ Passed 334ms
tests/responses-body-method-errors.test.ts ✅ Passed 414ms
tests/responses-cancel-timeout.test.ts ✅ Passed 262ms
tests/responses-cancel.test.ts ✅ Passed 253ms
tests/responses-compact-retries.test.ts ✅ Passed 283ms
tests/responses-compact.test.ts ✅ Passed 321ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 170ms
tests/responses-create-advanced.test.ts ✅ Passed 203ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.185s
tests/responses-create-errors.test.ts ✅ Passed 242ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 237ms
tests/responses-create-retries.test.ts ✅ Passed 356ms
tests/responses-create-stream-failures.test.ts ✅ Passed 300ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.161s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.499s
tests/responses-create-stream.test.ts ✅ Passed 102ms
tests/responses-create-terminal-states.test.ts ✅ Passed 289ms
tests/responses-create-timeout.test.ts ✅ Passed 283ms
tests/responses-create.test.ts ✅ Passed 327ms
tests/responses-delete.test.ts ✅ Passed 289ms
tests/responses-input-items-errors.test.ts ✅ Passed 323ms
tests/responses-input-items-list.test.ts ✅ Passed 189ms
tests/responses-input-items-options.test.ts ✅ Passed 251ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 307ms
tests/responses-input-tokens-count.test.ts ✅ Passed 297ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.12s
tests/responses-not-found-errors.test.ts ✅ Passed 365ms
tests/responses-parse.test.ts ✅ Passed 247ms
tests/responses-retrieve-retries.test.ts ✅ Passed 309ms
tests/responses-retrieve.test.ts ✅ Passed 289ms
tests/responses-stored-method-errors.test.ts ✅ Passed 842ms
tests/retry-behavior.test.ts ✅ Passed 3.094s
tests/sdk-error-shape.test.ts ✅ Passed 383ms

View OkTest run #30647418261

SDK merge (c65375632995) · head (8a44bffb75cf) · base (d6dad64d3189) · OkTest (91635c6a2723)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d2b8c11d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/package.json
Comment thread README.md Outdated

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two low-priority copy/paste compatibility issues are noted inline. The mTLS transport approach, endpoint selection, certificate-chain guidance, runtime-specific fetch wiring, manual-redirect protection, and cleanup otherwise look sound.

Comment thread README.md Outdated
Comment thread examples/package.json

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2ac20aaf6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/mtls/deno.mjs Outdated
@jbeckwith-oai
jbeckwith-oai enabled auto-merge (squash) July 31, 2026 16:30
@jbeckwith-oai
jbeckwith-oai merged commit 2cc5f96 into main Jul 31, 2026
23 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/api-mtls-http branch July 31, 2026 16:35
@stainless-app stainless-app Bot mentioned this pull request Jul 31, 2026
@github-actions github-actions Bot mentioned this pull request Aug 3, 2026
huanglianggit pushed a commit to huanglianggit/openai-node that referenced this pull request Aug 4, 2026
Automated Release PR
---


##
[7.4.0](openai/openai-node@v7.3.0...v7.4.0)
(2026-08-03)


### Features

* **api:** Add gpt-5.5 model and tool metadata fields
([openai#2049](openai#2049))
([6d8fb53](openai@6d8fb53))


### Bug Fixes

* defer release PR output parsing
([openai#2052](openai#2052))
([395bdde](openai@395bdde))


### Documentation

* add HTTP mTLS transport examples
([openai#2029](openai#2029))
([2cc5f96](openai@2cc5f96))


### Build System

* **deps-dev:** bump @smithy/hash-node from 4.3.5 to 4.4.15
([openai#2064](openai#2064))
([481b325](openai@481b325))
* **deps-dev:** bump @types/web from 0.0.194 to 0.0.354
([openai#2061](openai#2061))
([f61f267](openai@f61f267))
* **deps-dev:** bump publint from 0.2.12 to 0.3.22
([openai#2058](openai#2058))
([823d7df](openai@823d7df))
* **deps:** bump dotenv from 16.6.1 to 17.4.2
([openai#2065](openai#2065))
([3576574](openai@3576574))
* **deps:** bump fast-uri from 3.1.4 to 3.1.5 in
/ecosystem-tests/vercel-edge
([openai#2050](openai#2050))
([590982f](openai@590982f))
* **deps:** bump ip-address from 10.2.0 to 10.4.0 in
/ecosystem-tests/vercel-edge
([openai#2056](openai#2056))
([4d927de](openai@4d927de))
* migrate release workflow to upstream release-please
([openai#2048](openai#2048))
([d41c272](openai@d41c272))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
ci — 8a44bffb Deployed Jul 31, 2026 by jbeckwith-oai via examples #4859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants