@umituz/react-native-ai-fal-provider
v1.0.4
Published
FAL AI provider for React Native - implements IAIProvider interface for unified AI generation
Downloads
415
Maintainers
Readme
@umituz/react-native-ai-fal-provider
FAL AI provider service for React Native applications. Provides client wrapper, error handling, and React hooks.
Installation
npm install @umituz/react-native-ai-fal-provider @fal-ai/clientUsage
Initialize the Client
import { falClientService } from "@umituz/react-native-ai-fal-provider";
falClientService.initialize({
apiKey: "YOUR_FAL_API_KEY",
maxRetries: 3,
defaultTimeoutMs: 300000,
});Using the Hook
import { useFalGeneration } from "@umituz/react-native-ai-fal-provider";
function MyComponent() {
const { data, error, isLoading, generate, retry } = useFalGeneration({
timeoutMs: 120000,
onProgress: (status) => console.log("Progress:", status),
onError: (error) => console.log("Error:", error),
});
const handleGenerate = async () => {
await generate("fal-ai/flux/dev", {
prompt: "A beautiful sunset",
image_size: "landscape_16_9",
});
};
return (
// Your UI
);
}Direct Service Usage
import { falClientService } from "@umituz/react-native-ai-fal-provider";
const result = await falClientService.subscribe("fal-ai/flux/dev", {
prompt: "A beautiful sunset",
});Error Handling
import { mapFalError, isFalErrorRetryable } from "@umituz/react-native-ai-fal-provider";
try {
await falClientService.run("fal-ai/flux/dev", { prompt: "test" });
} catch (error) {
const errorInfo = mapFalError(error);
console.log("Error type:", errorInfo.type);
console.log("Message key:", errorInfo.messageKey);
console.log("Retryable:", errorInfo.retryable);
}API
falClientService
initialize(config)- Initialize the client with API keysubscribe(endpoint, input, options)- Subscribe to generation jobrun(endpoint, input)- Run a generation jobsubmitJob(endpoint, input)- Submit a job to queuegetJobStatus(endpoint, requestId)- Get job statusgetJobResult(endpoint, requestId)- Get job resultisInitialized()- Check if client is initializedreset()- Reset the client
useFalGeneration Hook
data- Generation resulterror- Error info if failedisLoading- Loading stateisRetryable- Whether error is retryablegenerate(endpoint, input)- Start generationretry()- Retry last generationreset()- Reset state
Error Utilities
mapFalError(error)- Map error to FalErrorInfoisFalErrorRetryable(error)- Check if error is retryablecategorizeFalError(error)- Get error category
License
MIT
