← Cloudflare AI Gateway / ai-gateway / usage / providers
Fal AI
Fal AI ↗ предоставляет доступ более чем к 600 готовым к использованию генеративным медиамоделям через единый API. Сервис предлагает крупнейшую в мире коллекцию открытых моделей для генерации изображений, видео, голоса и аудио, доступных с помощью одной строки кода.
Конечная точка
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/falСтруктура URL
При отправке запросов к Fal AI замените https://fal.run в URL, который вы сейчас используете с https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal.
Предварительные требования
Для запросов к Fal AI убедитесь, что у вас есть следующее:
- Account ID вашего AI Gateway.
- Название шлюза AI Gateway.
- Активный API-токен Fal AI.
- Название модели Fal AI, которую вы хотите использовать.
Синхронный API по умолчанию
По умолчанию запросы к эндпоинту Fal AI обращаются к синхронному API по адресу https://fal.run/<path>.
Пример cURL
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal/fal-ai/fast-sdxl \
--header 'Authorization: Key {fal_ai_token}' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "Make an image of a cat flying an aeroplane"
}'Пользовательские целевые URL-адреса
Если нужно обратиться к другому целевому URL, вы можете указать полный целевой URL Fal в x-fal-target-url заголовок.
Пример cURL с пользовательским целевым URL
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal \
--header 'Authorization: Bearer {fal_ai_token}' \
--header 'x-fal-target-url: https://queue.fal.run/fal-ai/bytedance/seedream/v4/edit' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.",
"image_urls": [
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png"
]
}'WebSocket API
Fal AI также поддерживает взаимодействие в реальном времени через WebSockets. Примеры и сведения о подключении по WebSocket см. в Документация Realtime WebSockets API.
Интеграция SDK для JavaScript
x-fal-target-url формат совместим с Fal SDK, поэтому AI Gateway можно легко передать как proxyUrl в SDK.
Пример SDK для JavaScript
import { fal } from "@fal-ai/client";
fal.config({
credentials: "{fal_ai_token}", // OR pass a cloudflare api token if using BYOK on AI Gateway
proxyUrl: "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal"
});
const result = await fal.subscribe("fal-ai/bytedance/seedream/v4/edit", {
"input": {
"prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.",
"image_urls": [
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png"
]
}
});
console.log(result.data.images[0]);