Fluent API Pattern
The Fluent API pattern in AI Dev Kit follows a consistent, beginner-friendly design that makes AI integration feel natural.
The Pattern
All generative AI requests follow this structure:
[Input].GENXxx().SetYyy(...).ExecuteAsync()1. Input (Entry Point)
The input can be various types:
// String
"Hello, AI!".GENCompletion()
// Texture2D
texture.GENInpaint("Add clouds")
// AudioClip
audioClip.GENTranscript()
// Prompt object
prompt.GENResponse()
// Message object
message.GENCompletion()
// ConversationItem
conversationItem.GENResponse()2. Request Factory (.GENXxx())
.GENXxx())The .GENXxx() methods create strongly-typed request objects:
Important: These methods do NOT perform any I/O or network calls. They only create configuration objects.
3. Configuration (.SetYyy())
.SetYyy())Chain configuration methods to customize the request:
4. Execution (.ExecuteAsync())
.ExecuteAsync())This is when the actual API call happens:
Why This Pattern?
✅ Readable
✅ Discoverable
Type a dot after any string, texture, or audio clip and IntelliSense shows you all available .GENXxx() methods.
✅ Type-Safe
✅ Flexible
You can store and reuse request objects:
Common Patterns
Pattern 1: One-liner
For quick, simple requests:
Pattern 2: Stored Configuration
When you need to reuse settings:
Pattern 3: Async/Await
Always use await or .Forget():
Pattern 4: Error Handling
Wrap in try-catch for robust error handling:
Method Naming Convention
GEN
Generate/Create content
GENCompletion, GENImage, GENSpeech
Upload
Upload files
UploadFile, UploadImage, UploadAudio
Download
Download files
DownloadFile
List
List resources
ListModels, ListVoices, ListFiles
Get
Retrieve single resource
GetModel, GetVoice, GetCredits
Delete
Remove resource
DeleteFile, DeleteModel
Count
Count tokens
CountTokens
Tokenize
Get token IDs
Tokenize
Extension Method Hosts
Different types can host different methods:
Next Steps
Request vs Execute - Understanding when API calls happen
Text Generation - Text generation examples
Image Generation - Image generation examples
Last updated