Back to Get APIs

GET /api/openai-function/:category/:subcategory

Download OpenAI function calling schema with complete implementation

Method

GET

Authentication

Not Required

Returns

Python file (.py)

Request Examples

cURL (Download)

curl -X GET https://api.genvrresearch.com/api/openai-function/imagegen/flux_dev \
  -o flux_dev_openai_function.py

Python (Download)

import requests

response = requests.get(
    'https://api.genvrresearch.com/api/openai-function/imagegen/flux_dev'
)

# Save to file
with open('flux_dev_openai_function.py', 'w') as f:
    f.write(response.text)

Downloaded File Contents

The downloaded Python file includes:

1.

OpenAI Function Definition

Complete JSON schema with all parameters, types, and descriptions

2.

Execution Function

Ready-to-use Python function that handles the complete GenVR API workflow

3.

Usage Example

Sample code showing how to use with OpenAI SDK

4.

Error Handling

Built-in error handling for network issues and generation failures

Example Generated File

Here's what you get when downloading for flux_dev:

imagegen_flux_dev_openai_function.py
#!/usr/bin/env python3
"""OpenAI Function for Flux Dev"""

FUNCTION_DEFINITION = {
  "type": "function",
  "function": {
    "name": "generate_imagegen_flux_dev",
    "description": "Generate content using the Flux Dev model",
    "parameters": {
      "type": "object",
      "properties": {
        "prompt": {
          "type": "string",
          "description": "Prompt"
        },
        "aspect_ratio": {
          "type": "string",
          "enum": ["1:1", "16:9", "21:9", ...],
          "default": "16:9"
        }
      },
      "required": ["prompt"]
    }
  }
}

def execute_generate_imagegen_flux_dev(arguments):
    # Complete GenVR API workflow
    # Generate → Poll Status → Get Response
    ...

Usage Example

# After downloading the file
from flux_dev_openai_function import FUNCTION_DEFINITION, execute_generate_imagegen_flux_dev
from openai import OpenAI

client = OpenAI(api_key="YOUR_OPENAI_KEY")

# Use in chat completion
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Generate a sunset image"}],
    tools=[FUNCTION_DEFINITION],
    tool_choice="auto"
)

# Handle function call
if response.choices[0].message.tool_calls:
    for tool_call in response.choices[0].message.tool_calls:
        import json
        args = json.loads(tool_call.function.arguments)
        result = execute_generate_imagegen_flux_dev(args)
        print(result)