OpenAIClient class

Available extensions

Constructors

OpenAIClient.new({String? apiKey, String baseUrl = "https://api.openai.com/v1/", Map<String, String>? headers, Client? httpClient})

Properties

apiKey String?
getter/setter pair
baseUrl Uri
latefinal
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>?
final
httpClient ↔ Client
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

acceptCall({required String callId, String sessionType = 'realtime', RealtimeModel? model, String? instructions, List<Modality>? outputModalities, RealtimeSessionAudio? audio, List<RealtimeFunctionTool>? tools, ToolChoice? toolChoice, dynamic maxOutputTokens, List<String>? include, Tracing? tracing, Map<String, dynamic>? prompt, dynamic truncation}) Future<void>

Available on OpenAIClient, provided by the RealtimeAPI extension

Accept an incoming SIP call and configure the realtime session that will handle it.
addUploadPart({required String uploadId, required Uint8List data}) Future<UploadPart>

Available on OpenAIClient, provided by the FilesAPI extension

Add a part (<= 64 MB) to an Upload.
cancelUpload(String uploadId) Future<Upload>

Available on OpenAIClient, provided by the FilesAPI extension

Cancel an Upload. No further parts may be added after cancellation.
cancelVectorStoreFileBatch({required String vectorStoreId, required String batchId}) Future<VectorStoreFileBatch>

Available on OpenAIClient, provided by the VectorStoresAPI extension

close() → void
completeUpload({required String uploadId, required List<String> partIds, String? md5}) Future<Upload>

Available on OpenAIClient, provided by the FilesAPI extension

Complete an Upload by specifying the ordered list of part IDs. Optionally pass an MD5 checksum of the entire file to verify integrity.
createCall({required String sdp, RealtimeSessionType type = RealtimeSessionType.realtime, RealtimeModel? model, String? instructions, dynamic maxOutputTokens, List<Modality>? outputModalities, RealtimeSessionAudio? audio, List<RealtimeFunctionTool>? tools, ToolChoice? toolChoice, Tracing? tracing, List<String>? include, Map<String, dynamic>? prompt, RealtimeTruncation? truncation, double? temperature}) Future<CreateRealtimeCallResponse>

Available on OpenAIClient, provided by the RealtimeAPI extension

Create a new Realtime API call over WebRTC and receive the SDP answer.
createContainer({required String name, ContainerExpiresAfter? expiresAfter, List<String>? fileIds}) Future<Container>

Available on OpenAIClient, provided by the ContainersAPI extension

Create a container.
createContainerFile({required String containerId, Uint8List? bytes, String? filename, String? fileId}) Future<ContainerFile>

Available on OpenAIClient, provided by the ContainersAPI extension

Create a container file either by uploading raw bytes (multipart) or by referencing an existing OpenAI File with fileId.
createEmbeddings({required dynamic input, required EmbeddingModel model, int? dimensions, String? encodingFormat, String? user}) Future<EmbeddingsResult>

Available on OpenAIClient, provided by the EmbeddingsAPI extension

Create text embeddings.
createImage({required String prompt, ImageGenerationBackground? background, String? model, ImageModeration? moderation, int? n, int? outputCompression, ImageOutputFormat? outputFormat, ImageOutputQuality? quality, ImageResponseFormat? responseFormat, ImageOutputSize? size, ImageStyle? style, String? user}) Future<ImagesResult>

Available on OpenAIClient, provided by the ImagesAPI extension

createImageVariation({required Uint8List imageBytes, required String filename, String? model, int? n, ImageResponseFormat? responseFormat, ImageOutputSize? size, String? user}) Future<ImagesResult>

Available on OpenAIClient, provided by the ImagesAPI extension

createRealtimeClientSecret({int? expiresAfterSeconds, String expiresAfterAnchor = 'created_at', Map<String, dynamic>? sessionJson, String sessionType = 'realtime', String? model, List<Modality>? outputModalities, AudioFormat? inputAudioFormat, AudioFormat? outputAudioFormat, SpeechVoice? voice, num? speed, String? instructions, dynamic maxOutputTokens, List<RealtimeFunctionTool>? tools, ToolChoice? toolChoice, Tracing? tracing, TurnDetection? turnDetection, NoiseReduction? inputAudioNoiseReduction, InputAudioTranscription? inputAudioTranscription, List<String>? include}) Future<CreateRealtimeClientSecretResponse>

Available on OpenAIClient, provided by the RealtimeAPI extension

Create an ephemeral client secret (ek_...) with an associated session config.
createRealtimeSession({RealtimeModel? model, List<Modality> modalities = const [Modality.audio, Modality.text], String? instructions, SpeechVoice? voice, BetaAudioFormat inputAudioFormat = BetaAudioFormat.pcm16, BetaAudioFormat outputAudioFormat = BetaAudioFormat.pcm16, InputAudioTranscription? inputAudioTranscription, NoiseReduction? inputAudioNoiseReduction, TurnDetection? turnDetection, List<RealtimeFunctionTool>? tools, ToolChoice? toolChoice, num? temperature, int? maxResponseOutputTokens, num? speed, Tracing? tracing, String? clientSecretAnchor, int? clientSecretSeconds}) Future<BetaRealtimeSession>

Available on OpenAIClient, provided by the BetaRealtimeAPI extension

createRealtimeSessionWebSocket({required RealtimeModel model, List<Modality> modalities = const [Modality.audio, Modality.text], String? instructions, SpeechVoice? voice, BetaAudioFormat inputAudioFormat = BetaAudioFormat.pcm16, BetaAudioFormat outputAudioFormat = BetaAudioFormat.pcm16, InputAudioTranscription? inputAudioTranscription, NoiseReduction? inputAudioNoiseReduction, TurnDetection? turnDetection, ToolChoice? toolChoice, num? temperature, int? maxResponseOutputTokens, num? speed, Tracing? tracing, String? clientSecretAnchor, int? clientSecretSeconds, List<RealtimeFunctionToolHandler>? initialTools}) Future<WebsocketRealtimeSessionController>

Available on OpenAIClient, provided by the RealtimeWebSocket extension

createRealtimeSessionWebSocket({required RealtimeModel model, List<Modality> modalities = const [Modality.audio, Modality.text], String? instructions, SpeechVoice? voice, BetaAudioFormat inputAudioFormat = BetaAudioFormat.pcm16, BetaAudioFormat outputAudioFormat = BetaAudioFormat.pcm16, InputAudioTranscription? inputAudioTranscription, NoiseReduction? inputAudioNoiseReduction, TurnDetection? turnDetection, ToolChoice? toolChoice, num? temperature, int? maxResponseOutputTokens, num? speed, Tracing? tracing, String? clientSecretAnchor, int? clientSecretSeconds, List<RealtimeFunctionToolHandler>? initialTools}) Future<WebsocketRealtimeSessionController>

Available on OpenAIClient, provided by the RealtimeIO extension

createRealtimeTranscriptionSession({BetaAudioFormat inputAudioFormat = BetaAudioFormat.pcm16, InputAudioTranscription? inputAudioTranscription, NoiseReduction? inputAudioNoiseReduction, TurnDetection? turnDetection, List<String>? include, String? clientSecretAnchor, int? clientSecretSeconds}) Future<RealtimeTranscriptionSession>

Available on OpenAIClient, provided by the BetaRealtimeAPI extension

createRealtimeWebsocket({required String token, RealtimeModel model = RealtimeModel.gptRealtime, String? callId, String? orgId, String? projectId}) Future<WebsocketRealtimeSessionController>

Available on OpenAIClient, provided by the RealtimeIO extension

createRealtimeWebsocket({required String token, RealtimeModel model = RealtimeModel.gptRealtime, String? callId, String? orgId, String? projectId}) Future<WebsocketRealtimeSessionController>

Available on OpenAIClient, provided by the RealtimeWebSocket extension

createResponse({bool? background, List<String>? include, Input? input, String? instructions, int? maxOutputTokens, Map<String, dynamic>? metadata, ChatModel? model, bool? parallelToolCalls, String? previousResponseId, ReasoningOptions? reasoning, bool? store, num? temperature, TextFormat? text, ToolChoice? toolChoice, List<Tool>? tools, num? topP, Truncation? truncation, String? user}) Future<Response>

Available on OpenAIClient, provided by the ResponsesAPI extension

createSpeech({required String input, required SpeechModel model, required SpeechVoice voice, String? instructions, SpeechResponseFormat? responseFormat, num? speed, String? streamFormat}) Future<Uint8List>

Available on OpenAIClient, provided by the AudioAPI extension

Generates TTS audio from text (/audio/speech).
createTranscription({required Uint8List fileBytes, required String filename, required AudioModel model, String? chunkingStrategy, List<String>? include, String? language, String? prompt, AudioResponseFormat responseFormat = AudioResponseFormat.json, num? temperature, List<String>? timestampGranularities}) Future<TranscriptionResult>

Available on OpenAIClient, provided by the TranscriptionAPI extension

Transcribe an audio file (blocking).
createUpload({required int bytes, required String filename, required String mimeType, required FilePurpose purpose, FileExpiresAfter? expiresAfter}) Future<Upload>

Available on OpenAIClient, provided by the FilesAPI extension

Create an Upload session for large files (multipart).
createVectorStore({String? name, List<String>? fileIds, Map<String, String>? metadata, ExpiresAfter? expiresAfter, ChunkingStrategy? chunkingStrategy}) Future<VectorStore>

Available on OpenAIClient, provided by the VectorStoresAPI extension

createVectorStoreFile({required String vectorStoreId, required String fileId, Map<String, dynamic>? attributes, ChunkingStrategy? chunkingStrategy}) Future<VectorStoreFile>

Available on OpenAIClient, provided by the VectorStoresAPI extension

createVectorStoreFileBatch({required String vectorStoreId, required List<String> fileIds, Map<String, dynamic>? attributes, ChunkingStrategy? chunkingStrategy}) Future<VectorStoreFileBatch>

Available on OpenAIClient, provided by the VectorStoresAPI extension

deleteContainer(String containerId) Future<ContainerDeleted>

Available on OpenAIClient, provided by the ContainersAPI extension

Delete a container by ID.
deleteContainerFile(String containerId, String fileId) Future<ContainerFileDeleted>

Available on OpenAIClient, provided by the ContainersAPI extension

Delete a container file by ID.
deleteFile(String fileId) Future<DeletionStatus>

Available on OpenAIClient, provided by the FilesAPI extension

Delete a file. Returns deletion status: {id, object:"file", deleted:true}
deleteVectorStore(String vectorStoreId) Future<DeletionStatus>

Available on OpenAIClient, provided by the VectorStoresAPI extension

deleteVectorStoreFile({required String vectorStoreId, required String fileId}) Future<DeletionStatus>

Available on OpenAIClient, provided by the VectorStoresAPI extension

editImage({required List<Uint8List> imageBytes, required List<String> filenames, required String prompt, ImageGenerationBackground? background, Uint8List? maskBytes, String? maskFilename, String? model, int? n, int? outputCompression, ImageOutputFormat? outputFormat, ImageOutputQuality? quality, ImageResponseFormat? responseFormat, ImageOutputSize? size, String? user}) Future<ImagesResult>

Available on OpenAIClient, provided by the ImagesAPI extension

getHeaders(Map<String, String> extra) Map<String, String>?
getRealtimeSDP({required RealtimeModel model, required String sdp, required String ephemeralKey}) Future<String>

Available on OpenAIClient, provided by the BetaRealtimeAPI extension

hangupCall({required String callId}) Future<void>

Available on OpenAIClient, provided by the RealtimeAPI extension

Hang up an active realtime call (SIP or WebRTC).
listContainerFiles(String containerId, {String? after, int? limit, String? order}) Future<ContainerFileList>

Available on OpenAIClient, provided by the ContainersAPI extension

List files inside a container (paginated).
listContainers({String? after, int? limit, String? order}) Future<ContainerList>

Available on OpenAIClient, provided by the ContainersAPI extension

List containers (paginated).
listFiles({String? after, int? limit, SortOrder? order, String? purpose}) Future<OpenAIFileList>

Available on OpenAIClient, provided by the FilesAPI extension

List files (optionally filter by purpose, paginate, and order).
listVectorStoreFiles(String vectorStoreId, {String? filter, String? after, String? before, int? limit, SortOrder? order}) Future<VectorStoreFileList>

Available on OpenAIClient, provided by the VectorStoresAPI extension

listVectorStoreFilesInBatch({required String vectorStoreId, required String batchId, String? filter, String? after, String? before, int? limit, SortOrder? order}) Future<VectorStoreFileBatchFilesList>

Available on OpenAIClient, provided by the VectorStoresAPI extension

listVectorStores({String? after, String? before, int? limit, SortOrder? order}) Future<VectorStoreList>

Available on OpenAIClient, provided by the VectorStoresAPI extension

modifyVectorStore(String vectorStoreId, {String? name, Map<String, String>? metadata, ExpiresAfter? expiresAfter, bool expiresAfterNull = false}) Future<VectorStore>

Available on OpenAIClient, provided by the VectorStoresAPI extension

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
postJson(String path, Map<String, dynamic> body, {String? contentType, Map<String, String>? headers}) Future<Response>
postText(String path, String body, {Map<String, String>? headers}) Future<Response>
referCall({required String callId, required String targetUri}) Future<void>

Available on OpenAIClient, provided by the RealtimeAPI extension

Transfer an active SIP call to another destination (SIP REFER).
rejectCall({required String callId, int? statusCode}) Future<void>

Available on OpenAIClient, provided by the RealtimeAPI extension

Reject an incoming call with an optional SIP status code. Default server behavior is 603 (Decline) if statusCode is omitted.
retrieveContainer(String containerId) Future<Container>

Available on OpenAIClient, provided by the ContainersAPI extension

Retrieve a single container by ID.
retrieveContainerFile(String containerId, String fileId) Future<ContainerFile>

Available on OpenAIClient, provided by the ContainersAPI extension

Retrieve a single container file’s metadata.
retrieveContainerFileContent(String containerId, String fileId) Future<Uint8List>

Available on OpenAIClient, provided by the ContainersAPI extension

Download the container file content as bytes.
retrieveFile(String fileId) Future<OpenAIFile>

Available on OpenAIClient, provided by the FilesAPI extension

Retrieve a single file’s metadata.
retrieveFileContent(String fileId) Future<Uint8List>

Available on OpenAIClient, provided by the FilesAPI extension

Download file contents as bytes. Caller can persist them as needed.
retrieveVectorStore(String vectorStoreId) Future<VectorStore>

Available on OpenAIClient, provided by the VectorStoresAPI extension

retrieveVectorStoreFile({required String vectorStoreId, required String fileId}) Future<VectorStoreFile>

Available on OpenAIClient, provided by the VectorStoresAPI extension

retrieveVectorStoreFileBatch({required String vectorStoreId, required String batchId}) Future<VectorStoreFileBatch>

Available on OpenAIClient, provided by the VectorStoresAPI extension

retrieveVectorStoreFileContent({required String vectorStoreId, required String fileId}) Future<Map<String, dynamic>>

Available on OpenAIClient, provided by the VectorStoresAPI extension

searchVectorStore(String vectorStoreId, {required dynamic query, FileSearchFilter? filters, int? maxNumResults, RankingOptions? rankingOptions, bool? rewriteQuery}) Future<VectorStoreSearchResultsPage>

Available on OpenAIClient, provided by the VectorStoresAPI extension

streamContainerFileContent(String containerId, String fileId) Stream<Uint8List>

Available on OpenAIClient, provided by the ContainersAPI extension

Stream the container file content as chunks (useful for large files).
streamJson(String path, Map<String, dynamic> body, {Map<String, String>? headers}) SseClient
streamJsonData(String path, Map<String, dynamic> body, {Map<String, dynamic>? headers}) Stream<Uint8List>
POST a JSON body and expose the (chunked) response body as a byte stream.
streamResponse({bool? background, List<String>? include, Input? input, String? instructions, int? maxOutputTokens, Map<String, dynamic>? metadata, ChatModel? model, bool? parallelToolCalls, String? previousResponseId, ReasoningOptions? reasoning, bool? store, num? temperature, TextFormat? text, ToolChoice? toolChoice, List<Tool>? tools, num? topP, Truncation? truncation, String? user}) Future<ResponseStream>

Available on OpenAIClient, provided by the ResponsesAPI extension

streamSpeechData({required String input, required SpeechModel model, required SpeechVoice voice, String? instructions, SpeechResponseFormat? responseFormat, num? speed, String streamFormat = 'sse', List<String>? include}) Future<Stream<List<int>>>

Available on OpenAIClient, provided by the AudioAPI extension

streamSpeechEvents({required String input, required SpeechModel model, required SpeechVoice voice, String? instructions, SpeechResponseFormat? responseFormat, num? speed, String streamFormat = 'sse', List<String>? include}) Future<SpeechStream>

Available on OpenAIClient, provided by the AudioAPI extension

Create TTS and stream it back chunk-by-chunk as SSE.
streamTranscription({required Uint8List fileBytes, required String filename, required AudioModel model, String? chunkingStrategy, List<String>? include, String? language, String? prompt, AudioResponseFormat responseFormat = AudioResponseFormat.json, num? temperature, List<String>? timestampGranularities}) Future<TranscriptionStream>

Available on OpenAIClient, provided by the TranscriptionAPI extension

Transcribe an audio file and stream text deltas as SSE.
toString() String
A string representation of this object.
inherited
updateVectorStoreFileAttributes({required String vectorStoreId, required String fileId, required Map<String, dynamic> attributes}) Future<VectorStoreFile>

Available on OpenAIClient, provided by the VectorStoresAPI extension

uploadFileBytes({required FilePurpose purpose, required Uint8List fileBytes, required String filename, FileExpiresAfter? expiresAfter, String? mimeType}) Future<OpenAIFile>

Available on OpenAIClient, provided by the FilesAPI extension

Upload a file from raw bytes.

Operators

operator ==(Object other) bool
The equality operator.
inherited