SpyBara
Go Premium

Reference 2026-08-10 22:00 UTC to 2026-08-11 03:59 UTC

1 file changed +18 −3. View all changes and history on the product overview
2026
Tue 11 03:59 Mon 10 22:00 Sat 8 00:59 Fri 7 21:59 Thu 6 18:59 Wed 5 02:01 Tue 4 22:59 Mon 3 21:58 Sat 1 01:00

ruby/index.md +18 −3

Details

82 82 

83Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.3/o/pathname) instance, [`StringIO`](https://rubyapi.org/3.3/o/stringio), or more.83Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.3/o/pathname) instance, [`StringIO`](https://rubyapi.org/3.3/o/stringio), or more.

84 84 

85Raw `String` and `StringIO` values, and `IO` objects without a path, do not carry format-identifying metadata. The SDK sends them using the fallback filename `upload`; raw `String` values default to `text/plain`, while `StringIO` and pathless `IO` values default to `application/octet-stream`. For format-sensitive endpoints, such as audio transcriptions, wrap each value in `OpenAI::FilePart` and provide an extension-bearing filename and content type.

86 

85```ruby87```ruby

86require "pathname"88require "pathname"

87 89 


93 95 

94puts(file_object.id)96puts(file_object.id)

95 97 

96# Or, to control the filename and/or content type:98# For format-sensitive uploads, provide the filename and content type:

97image = OpenAI::FilePart.new(Pathname('dog.jpg'), content_type: 'image/jpeg')99audio_data = StringIO.new(File.binread("audio.wav"))

100audio = OpenAI::FilePart.new(

101 audio_data,

102 filename: "audio.wav",

103 content_type: "audio/wav"

104)

105transcription = openai.audio.transcriptions.create(

106 model: "gpt-4o-transcribe",

107 file: audio

108)

109puts(transcription.text)

110 

111# FilePart also accepts a Pathname:

112image = OpenAI::FilePart.new(Pathname("dog.jpg"), content_type: "image/jpeg")

98edited = openai.images.edit(113edited = openai.images.edit(

99 prompt: "make this image look like a painting",114 prompt: "make this image look like a painting",

100 model: "gpt-image-1",115 model: "gpt-image-1",

101 size: '1024x1024',116 size: "1024x1024",

102 image: image117 image: image

103)118)

104 119