### Install Kavel Go SDK Source: https://kavel.readthedocs.io/en/latest/sdk/go Use the go get command to add the Kavel Go SDK to your project. ```bash go get github.com/hanshs474/kavel-go ``` -------------------------------- ### Run Example Source: https://kavel.readthedocs.io/en/latest/sdk/go Execute the example provided by the SDK directly using go run. ```bash go run github.com/hanshs474/kavel-go/example@latest "an isometric coffee shop, pastel palette" ``` -------------------------------- ### Install Kavel SDK Source: https://kavel.readthedocs.io/en/latest/sdk/python Install the Kavel package using pip. This library uses only the standard library and is compatible with restricted environments like hosted notebooks. ```bash pip install kavel ``` -------------------------------- ### Install and use kavel blocking image generation Source: https://kavel.readthedocs.io/en/latest/sdk/rust Install the kavel crate with cargo add, then generate an image using the blocking API. The example sets a 16:9 aspect ratio and handles Quota, Rejected, and generic errors. This API is blocking and built on ureq, so it does not pull an async runtime into your tree. ```bash cargo add kavel ``` ```rust let opts = kavel::Options { aspect_ratio: "16:9".into(), ..Default::default() }; match kavel::generate("a red paper kite over a green hill, soft morning light", &opts) { Ok(img) => println!("{}", img.url, img.watermarked), Err(kavel::Error::Quota(why)) => eprintln!("come back tomorrow: {why}"), Err(kavel::Error::Rejected) => eprintln!("reword the prompt"), Err(e) => eprintln!("{e}"), } ``` -------------------------------- ### Install Kavel PHP SDK with Composer Source: https://kavel.readthedocs.io/en/latest/sdk/php Install the Kavel PHP SDK using Composer. Requires PHP 8.1+ and ext-curl. ```bash composer require hanshs474/kavel ``` -------------------------------- ### Install Kavel .NET SDK with dotnet add package Source: https://kavel.readthedocs.io/en/latest/sdk/dotnet Adds the Kavel NuGet package to a .NET project. Run this command in the project directory. ```bash dotnet add package Kavel ``` -------------------------------- ### Install kavel gem Source: https://kavel.readthedocs.io/en/latest/sdk/ruby Installs the kavel Ruby gem from RubyGems. ```bash gem install kavel ``` -------------------------------- ### Install Kavel TypeScript SDK with Deno Source: https://kavel.readthedocs.io/en/latest/sdk/typescript Adds the @kavel/kavel package using the Deno package manager. The SDK has zero dependencies, relying only on fetch and Web Crypto. ```bash deno add jsr:@kavel/kavel ``` -------------------------------- ### Generate an image with Kavel PHP SDK Source: https://kavel.readthedocs.io/en/latest/sdk/php Example of generating an image using the Kavel class. The call blocks for a minute or more, so it should be run from a queue worker or CLI command, not a web request. ```php use Kavel\Kavel; use Kavel\KavelException; try { $img = (new Kavel())->generate('a small wooden sailboat on a calm teal lake, golden hour', '16:9'); echo $img->url; } catch (KavelException $e) { if ($e->kind === KavelException::QUOTA) { /* retry tomorrow */ } } ``` -------------------------------- ### Generate image with curl using x-anon-id Source: https://kavel.readthedocs.io/en/latest/sdk/http Sends a POST request to the generate endpoint with a random client ID. The response contains a task ID that must be used for polling. The example uses the 'kie' provider, 'kavel-image-v1' model, and 'text-to-image' scene. ```bash ID="demo-$RANDOM" curl -s https://www.kavel.ai/api/ai/generate \ -H "content-type: application/json" -H "x-anon-id: $ID" \ -d '{"provider":"kie","mediaType":"image","model":"kavel-image-v1","scene":"text-to-image", "prompt":"a lighthouse in fog, cinematic","options":{"aspect_ratio":"16:9"}}' # {"code":0,"message":"ok","data":{"id":"", ...}} ``` -------------------------------- ### Add Kavel package with dart pub add or flutter pub add Source: https://kavel.readthedocs.io/en/latest/sdk/dart Install the Kavel package in a Dart or Flutter project. The command uses 'dart pub add kavel' for Dart projects and 'flutter pub add kavel' for Flutter projects. ```bash dart pub add kavel # or: flutter pub add kavel ``` -------------------------------- ### Generate and poll an image with curl using $KAVEL_API_KEY Source: https://kavel.readthedocs.io/en/latest/api-key Raw HTTP calls to the Kavel API. The first starts an image generation task and returns a task id; the second polls that task until data.status is "success". On a paid plan, data.cleanImages holds the unwatermarked file. Both use the Authorization: Bearer $KAVEL_API_KEY header. ```bash curl https://www.kavel.ai/api/ai/generate \ -H "Authorization: Bearer $KAVEL_API_KEY" -H "Content-Type: application/json" \ -d '{"provider":"kie","mediaType":"image","model":"gpt-image-2","scene":"text-to-image", "prompt":"a glass perfume bottle on wet black stone, studio light","options":{"aspect_ratio":"4:5"}}' # {"code":0,"message":"ok","data":{"id":"", ...}} ``` ```bash curl https://www.kavel.ai/api/ai/query \ -H "Authorization: Bearer $KAVEL_API_KEY" -H "Content-Type: application/json" \ -d '{"taskId":""}' # repeat until data.status is "success"; data.cleanImages holds the unwatermarked file on a paid plan ``` -------------------------------- ### Poll for generated image with curl Source: https://kavel.readthedocs.io/en/latest/sdk/http Sends a GET request to the anon-query endpoint with the task ID and the same client ID. Poll every ~5 seconds until the 'data.images[0]' field appears. ```bash curl -s "https://www.kavel.ai/api/ai/anon-query?taskId=&provider=kie&mediaType=image" -H "x-anon-id: $ID" # repeat every ~5 s until data.images[0] appears ``` -------------------------------- ### Batch generation with credit budget and progress tracking Source: https://kavel.readthedocs.io/en/latest/recipes/batch Processes prompts from prompts.txt, deducting 5 credits per generation from a 30-credit budget. Stops cleanly when budget is insufficient or on a 429/ceiling error, and writes the number of completed items to progress.txt after each item. Refused prompts still consume credits, so they are recorded as None. ```python from kavel import generate, KavelError prompts = open("prompts.txt").read().splitlines() budget = 30 done = [] for p in prompts: if budget < 5: break # stop cleanly; resume tomorrow from len(done) try: done.append((p, generate(p))) budget -= 5 except KavelError as e: if "429" in str(e) or "ceiling" in str(e).lower(): break done.append((p, None)) # refused prompt: credits are spent either way open("progress.txt", "w").write(str(len(done))) ``` -------------------------------- ### Generate an image with KavelClient Source: https://kavel.readthedocs.io/en/latest/sdk/dotnet Creates a KavelClient and generates an image with a prompt and aspect ratio. The result's Url is printed. Targets net8.0 and netstandard2.0. Branch on KavelException.Kind. Pass apiKey: or set KAVEL_API_KEY to use your account. ```csharp using Kavel; var kavel = new KavelClient(); var img = await kavel.GenerateAsync("a cozy reading nook with a green armchair, warm lamp light", aspectRatio: "4:3"); Console.WriteLine(img.Url); ``` -------------------------------- ### Generate and Edit Images Source: https://kavel.readthedocs.io/en/latest/sdk/go Generate an image using kavel.Generate and edit it using kavel.Edit. Handle the kavel.ErrQuota sentinel error to manage usage limits. ```go img, err := kavel.Generate(ctx, "matte black ceramic mug on pale oak, soft window light", kavel.Options{AspectRatio: "16:9"}) if errors.Is(err, kavel.ErrQuota) { // this machine is done for today } fmt.Println(img.URL, img.Watermarked) edited, err := kavel.Edit(ctx, img.URL, "place the mug on white marble", kavel.Options{}) ``` -------------------------------- ### Generate Image with Reference URL Source: https://kavel.readthedocs.io/en/latest/sdk/python Pass an image_url to the generate function to use the prompt as an instruction for modifying an existing image. ```python url = generate( "restyle the hair into a shoulder-length layered cut, keep the same face, skin and lighting", image_url="https://example.com/portrait.jpg", ) ``` -------------------------------- ### Generate and edit an image with Kavel Source: https://kavel.readthedocs.io/en/latest/sdk/ruby Generates an image with Kavel.generate, prints its URL, then edits it with Kavel.edit. Rescue by intent using Kavel::QuotaError, Kavel::RejectedError, Kavel::SignInError, or Kavel::AuthError. Pass api_key: or set KAVEL_API_KEY to run on your account. ```ruby require "kavel" img = Kavel.generate("a stack of three colorful macarons, studio light", aspect_ratio: "4:3") puts img.url edited = Kavel.edit(img.url, "put the macarons on a pale marble slab; keep the colors") ``` -------------------------------- ### Generate Image from Prompt Source: https://kavel.readthedocs.io/en/latest/sdk/python Use the generate function to create an image based on a text prompt. ```python from kavel import generate url = generate("a paper-cut layered mountain range at dusk, warm rim light") ``` -------------------------------- ### Generate an image with Kavel TypeScript SDK Source: https://kavel.readthedocs.io/en/latest/sdk/typescript Imports generate, edit, and KavelError from @kavel/kavel. Calls generate with a prompt and options including aspectRatio and an AbortController signal. Catches KavelError with kind 'quota' to log a daily ceiling message. The signal allows a UI to cancel a queued job. ```typescript import { generate, edit, KavelError } from "@kavel/kavel"; const controller = new AbortController(); try { const img = await generate("a bowl of ramen, overhead shot, steam, dark slate table", { aspectRatio: "4:3", signal: controller.signal, }); console.log(img.url); } catch (e) { if (e instanceof KavelError && e.kind === "quota") console.log("daily ceiling reached"); else throw e; } ``` -------------------------------- ### Generate an image with Kavel Source: https://kavel.readthedocs.io/en/latest/sdk/dart Creates a Kavel instance and generates an image using a text prompt and aspect ratio. The result is an image object with a URL. Without an API key, no secret is shipped in the app; using apiKey: runs calls on your account, which is recommended for server-side use. ```dart final kavel = Kavel(); final img = await kavel.generate('a glass teapot with blooming flower tea, soft backlight', aspectRatio: '4:5'); print(img.url); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.