Skip to main content
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 port API. Choose your preferred programming language below to get started:

JavaScript/Node.js

To get started, install the client package and configure it with your API key:
npm install @portmoda/client
Set your API key as an environment variable:
export PORT_KEY="your-api-key-here"
Once configured, you can invoke our Model API endpoint using the port client:
import { port } from "@portmoda/client";

// Optionally, configure the client with a different API key other than the one set in the environment variable
port.config({
  credentials: "YOUR_PORT_KEY",
});

const result = await port.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"
  },
});

Python

Install the Python client library using pip:
pip install port-client
Set your API key as an environment variable:
export PORT_KEY="your-api-key-here"
Configure and use the client:
import port_client

result = port_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)

Java

Add the Java client library to your project using your preferred build system:
implementation("ai.port.client:port-client:0.1.5")
Set your API key as an environment variable:
export PORT_KEY="your-api-key-here"
Configure and use the client:
import ai.port.client.*;
import ai.port.client.queue.*;
import java.util.Map;
import com.google.gson.JsonObject;
import java.util.function.Consumer;

ClientConfig config = ClientConfig.builder()
    .withCredentials(CredentialsResolver.fromEnv())
    .build();

PortClient client = PortClient.withConfig(config);
Map<String, Object> input = Map.of(
    "prompt", "A rabbit wearing glasses reading a book under a mushroom in watercolor style.",
    "width", 1024,
    "height", 768,
    "output_format", "jpeg"
);

Consumer<QueueStatus.StatusUpdate> statusUpdateHandler = update -> {
    String status = update.getStatus().toString();
    String message = String.format("\nStatus Update: %s, Request ID: %s",
        status, update.getRequestId());
    System.out.println(message);
};

SubscribeOptions<JsonObject> options = SubscribeOptions.<JsonObject>builder()
    .input(input)
    .resultType(JsonObject.class)
    .onQueueUpdate(statusUpdateHandler)
    .logs(true)
    .build();

Output<JsonObject> response = client.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", options);
System.out.println("Completed!");
System.out.println(response.getData());

Next Steps

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.