# yaml-language-server: $schema=../../tools/ai-codegen/codegen.schema.json
# To update, pin the latest openai/openai-openapi commit and regenerate from the repo root:
# nix develop -c node packages/tools/ai-codegen/src/bin.ts generate --provider openai
spec: https://raw.githubusercontent.com/openai/openai-openapi/e95c0fe615f45a19e8878af923a729948445a6bd/openapi.yaml
output: src/Generated.ts
name: OpenAiClient
header: |
/**
* @stability unstable
* @since 1.0.0
*/
patches:
# Preserve the optional `name` field removed upstream.
- '[{"op":"add","path":"/components/schemas/ResponseFunctionCallArgumentsDoneEvent/properties/name","value":{"type":"string","description":"The name of the function that was called."}}]'
# Keep cache_write_tokens and access_programs optional for older and OpenAI-compatible servers.
- '[{"op":"replace","path":"/components/schemas/ResponseUsage/properties/input_tokens_details/required","value":["cached_tokens"]}]'
- '[{"op":"replace","path":"/components/schemas/Response/allOf/2/required","value":["id","object","created_at","error","incomplete_details","instructions","model","tools","output","parallel_tool_calls","metadata","tool_choice","temperature","top_p"]}]'
# Also accept the legacy `in-memory` spelling
- '[{"op":"add","path":"/components/schemas/PromptCacheRetentionEnum/enum/1","value":"in-memory"}]'
- '[{"op":"replace","path":"/components/schemas/OpenAIFile/properties/expires_at","value":{"anyOf":[{"type":"integer","format":"unixtime","description":"The Unix timestamp (in seconds) for when the file will expire."},{"type":"null"}]}}]'
- '[{"op":"replace","path":"/components/schemas/OpenAIFile/properties/status_details/type","value":["string","null"]}]'
# Remove when the upstream schema includes named API sources: https://github.com/openai/openai-openapi/issues/573
- '[{"op":"replace","path":"/components/schemas/WebSearchActionSearch/properties/sources/items","value":{"anyOf":[{"type":"object","title":"Web search source","description":"A source used in the search.\n","properties":{"type":{"type":"string","enum":["url"],"description":"The type of source. Always `url`.\n","x-stainless-const":true},"url":{"type":"string","format":"uri","description":"The URL of the source.\n"}},"required":["type","url"]},{"type":"object","title":"Web search API source","description":"An API source used in the search.\n","properties":{"type":{"type":"string","enum":["api"],"description":"The type of source. Always `api`.\n","x-stainless-const":true},"name":{"type":"string","description":"The name of the API source, such as `oai-weather`, `oai-sports`, or `oai-finance`.\n"}},"required":["type","name"]}]}}]'
# OpenAI may omit the find-in-page URL: https://github.com/openai/openai-openapi/issues/571
# Also tolerate omitted patterns without substituting a value.
- '[{"op":"replace","path":"/components/schemas/WebSearchActionFind/required","value":["type"]}]'
# Add missing keepalive stream event support
- '[{"op":"add","path":"/components/schemas/ResponseKeepAliveEvent","value":{"type":"object","title":"Keep alive","description":"A keepalive event emitted during long-running response streams.","properties":{"type":{"type":"string","enum":["keepalive"],"description":"The type of the keepalive event. Always `keepalive`.","default":"keepalive","x-stainless-const":true},"sequence_number":{"type":"integer","description":"The sequence number of this keepalive event."}},"required":["type","sequence_number"]}}]'
- '[{"op":"add","path":"/components/schemas/ResponseStreamEvent/anyOf/-","value":{"$ref":"#/components/schemas/ResponseKeepAliveEvent"}}]'
# Add missing ResponseApplyPatchCallOperationDiffDeltaEvent schema
- '[{"op":"add","path":"/components/schemas/ResponseApplyPatchCallOperationDiffDeltaEvent","value":{"title":"ResponseApplyPatchCallOperationDiffDelta","type":"object","description":"Event representing a delta for an apply_patch tool call operation diff.","properties":{"type":{"type":"string","enum":["response.apply_patch_call_operation_diff.delta"],"description":"The event type identifier.","x-stainless-const":true},"sequence_number":{"type":"integer","description":"The sequence number of this event."},"output_index":{"type":"integer","description":"The index of the output this delta applies to."},"item_id":{"type":"string","description":"Unique identifier for the API item associated with this event."},"delta":{"type":"string","description":"The incremental diff data for the apply_patch tool call."}},"required":["type","output_index","item_id","delta","sequence_number"]}}]'
# Add missing ResponseApplyPatchCallOperationDiffDoneEvent schema (delta is optional - not always sent by OpenAI)
- '[{"op":"add","path":"/components/schemas/ResponseApplyPatchCallOperationDiffDoneEvent","value":{"title":"ResponseApplyPatchCallOperationDiffDone","type":"object","description":"Event indicating that the operation diff for an apply_patch tool call is complete.","properties":{"type":{"type":"string","enum":["response.apply_patch_call_operation_diff.done"],"description":"The event type identifier.","x-stainless-const":true},"sequence_number":{"type":"integer","description":"The sequence number of this event."},"output_index":{"type":"integer","description":"The index of the output this event applies to."},"item_id":{"type":"string","description":"Unique identifier for the API item associated with this event."},"delta":{"type":"string","description":"The final diff data for the apply_patch tool call."}},"required":["type","output_index","item_id","sequence_number"]}}]'
# Add both events to ResponseStreamEvent anyOf array
- '[{"op":"add","path":"/components/schemas/ResponseStreamEvent/anyOf/-","value":{"$ref":"#/components/schemas/ResponseApplyPatchCallOperationDiffDeltaEvent"}}]'
- '[{"op":"add","path":"/components/schemas/ResponseStreamEvent/anyOf/-","value":{"$ref":"#/components/schemas/ResponseApplyPatchCallOperationDiffDoneEvent"}}]'
excludeAnnotations:
- examples
- default
disableAdditionalProperties: true
replacements:
# Schema.Unknown doesn't work with Schema.toCodecJson (used by HttpClientResponse.schemaBodyJson)
# Replace with Schema.Json which properly handles arbitrary JSON values
- from: "Schema.Record(Schema.String, Schema.Unknown)"
to: "Schema.Record(Schema.String, Schema.Json)"
- from: "{ readonly [x: string]: unknown }"
to: "{ readonly [x: string]: Schema.Json }"