Skip to content

Codex: prompt_cache_key can exceed OpenAI's 64-char limit, causing 400 mid-turn #4720

@kobiebendalak

Description

@kobiebendalak

What happened?

OpenAI rejects Codex Responses requests whose prompt_cache_key is >64 chars:

Error: Invalid 'prompt_cache_key': string too long. Expected a string with maximum length 64, but got a string with length 67 instead.

At packages/ai/src/providers/openai-codex-responses.ts:381 Pi sets prompt_cache_key: options?.sessionId with no length clamp. Session ids from composite forms (e.g. client_<uuid>:<agent_type>) routinely exceed 64.

Steps to reproduce

  1. Invoke streamOpenAICodexResponses (or streamSimpleOpenAICodexResponses) with an options.sessionId longer than 64 chars — e.g. client_d4a85a75-2483-4b2d-b15b-b97d182711ef:openai-codex (69 chars).
  2. First response frame returns the 400 above; turn fails before any output.

Expected behavior

Pi clamps prompt_cache_key to 64 chars before sending (deterministic prefix slice keeps prefix caching working). The turn completes normally.

Version

@earendil-works/pi-ai from current main (verified against packages/ai/src/providers/openai-codex-responses.ts:381 as of 2026-05-19).

Proposed fix

5-line helper at the file's config-constants block; one-line change at the call site. Branch ready (fix/codex-prompt-cache-key-length on kobiebendalak/pi); happy to re-open the PR once an lgtmi lands here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    inprogressIssue is being worked on

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions