Skip to main content
Version: 11 - TBD

ConnectorTypeOPENAI

class connector_types.connector_type_openai.ConnectorTypeOPENAI

Access OpenAI APIs

Input Schema

  • schema_version

    Type: string

  • authentication

    Type: anyOf

  • endpoint

    The endpoint to use.

    Type: anyOf

  • mode

    Type: anyOf

Output Schema

Example

OpenAI API key authentication and chat completion

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
result = this.connect(
connector_type='OPENAI',
authentication={
'authentication_method': 'openai',
'api_key': '...',
},
endpoint={
'endpoint_type': 'openai',
},
mode={
'mode_name': 'chat_completion',
'model': 'gpt-3.5-turbo',
'messages': ['Hello world!'],
},
).get('output_value')['result']
return this.success(result)

Azure API key authentication and image generation

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
result = this.connect(
connector_type='OPENAI',
authentication={
'authentication_method': 'azure_api_key',
'api_key': '...',
},
endpoint={
'endpoint_type': 'azure',
'api_version': '2024-05-13',
'api_base': 'https://...',
'deployment_id': '...',
},
mode={
'mode_name': 'image_generate',
'model': '...',
'prompt': '...',
'n': 1,
'size': '512x512',
'response_format': 'b64_json',
},
).get('output_value')['result']
return this.success(result)

Azure AD authentication and image edit

import flow_api

def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
image = system.file('image.png').get_base64_content()
mask = system.file('mask.png').get_base64_content()
result = this.connect(
connector_type='OPENAI',
authentication={
'authentication_method': 'azure_ad',
'tenant_id': '...',
'client_id': '...',
'client_secret': '...',
},
endpoint={
'endpoint_type': 'azure',
'api_version': '2024-05-13',
'api_base': 'https://...',
'deployment_id': '...',
},
mode={
'mode_name': 'image_edit',
'image': image,
'mask': mask,
'prompt': '...',
'n': 1,
'size': '1024x1024',
'response_format': 'url',
},
).get('output_value')['result']
return this.success(result)