Back to projects

Freepik/Magnific API Platform

End-to-end design and implementation of Freepik/Magnific's public API platform: AI generation (image, video, audio), stock content, task status and account APIs. OpenAPI specification, FastAPI server, APISIX gateway (rate limits, cost tracking, API keys), billing and public documentation.

Context

Freepik/Magnific runs a public AI API platform that exposes image and video generation models to developers building products on top of Freepik/Magnific's AI stack. As the platform grew from a handful of endpoints to dozens of AI models, the underlying process — from an OpenAPI spec to a production endpoint, with billing and public docs — needed a consistent, repeatable path instead of one-off work per endpoint.

What I built

I worked across the full lifecycle of this platform: authoring and evolving the OpenAPI specification that defines every endpoint's parameters and responses, implementing the FastAPI server that turns specs into working endpoints, wiring rate limits and per-model billing into the gateway, and shipping the public API reference that developers use to integrate.

This includes the API keys and billing surface: generating and revoking keys, tracking usage per plan (free / pro / enterprise), and translating model-specific pricing (per generation, per second of video, per resolution) into gateway-level cost rules.

Architecture

The pipeline has four stages that map cleanly to four concerns:

  1. Specification — an OpenAPI contract defines each endpoint's request/response shape, kept in sync as new models and parameters are added.
  2. Server — a FastAPI application implements the contract: request validation, task orchestration and webhook delivery for long-running generations.
  3. Gateway — an open-source API gateway (Apache APISIX) sits in front of the server, enforcing per-tier rate limits and computing usage-based cost per request.
  4. Docs — the public API reference is generated from the same spec, so documentation never drifts from what the gateway actually accepts.

A billing service (implemented in PHP) reads gateway usage data and product definitions to bill customers per plan, keeping the pricing model decoupled from the request-handling path.

Integrations: beyond one model per call

The platform exposes more than AI generation models. On the same spec → server → gateway → docs pipeline it also serves stock content APIs (search and download), task-status endpoints and account utilities — plus the Flows API, the orchestration layer that chains multiple models behind a single call: a flow describes a sequence of steps (e.g. generate → upscale → convert to video) and the platform runs it as a single task, metering usage per step so cost reflects the models actually invoked.

Outcome

The result is a public AI API platform serving image and video generation models at scale, with a documented, repeatable process for adding new capability without touching billing or gateway code by hand. The production version is live, with full reference docs at docs.magnific.com.