In this guide, we’ll walk you through using one of our popular model endpoints, such as black-forest-labs/flux-kontext-pro/text-to-image.
Before diving in, ensure you have an API key from your dashboard,
which is required for authenticating your requests to the sunra API.Choose your preferred programming language below to get started:
To get started, install the client package and configure it with your API key:
Copy
npm install @sunra/client
Set your API key as an environment variable:
Copy
export SUNRA_KEY="your-api-key-here"
Once configured, you can invoke our Model API endpoint using the sunra client:
Copy
import { sunra } from "@sunra/client";// Optionally, configure the client with a different API key other than the one set in the environment variablesunra.config({ credentials: "YOUR_SUNRA_KEY",});const result = await sunra.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", { input: { prompt: "A rabbit wearing glasses reading a book under a mushroom in watercolor style.", width: 1024, height: 768, output_format: "jpeg" },});
import sunra_clientresult = sunra_client.subscribe( "black-forest-labs/flux-kontext-pro/text-to-image", arguments={ "prompt": "A rabbit wearing glasses reading a book under a mushroom in watercolor style.", "width": 1024, "height": 768, "output_format": "jpeg" }, with_logs=True, on_enqueue=print, on_queue_update=print,)print(result)
We offer various models like Flux kontext pro and Kling v2 master as ready-to-use APIs. Explore these on our Model Playground.To use a model, visit its “API” tab to find the URL, source code, and usage examples, helping you integrate it seamlessly into your applications.For more detailed information about each client library, visit our client libraries documentation.