Media (Images, Speech, Transcription)
Image Generation
Section titled “Image Generation”Generate images from text prompts:
Basic image generation with a text prompt
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import CreateImageRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = CreateImageRequest.from_json("{\"model\":\"dall-e-3\",\"n\":1,\"prompt\":\"A white cat sitting on a windowsill\",\"size\":\"1024x1024\"}") result = await client.image_generate(req) print(result.data) print(result.data[0].url)
asyncio.run(main())Basic image generation with a text prompt
import { createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.imageGenerate({ model: "dall-e-3", n: 1, prompt: "A white cat sitting on a windowsill", size: "1024x1024" }); console.log(result.data); console.log(result.data?.[0]?.url);}
void main();Basic image generation with a text prompt
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"model":"dall-e-3","n":1,"prompt":"A white cat sitting on a windowsill","size":"1024x1024"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.image_generate(req).await.expect("call failed"); println!("{:?}", result.data); println!("{:?}", result.data[0].url);}Basic image generation with a text prompt
package main
import ( "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func ptr[T any](value T) *T { return &value }func main() { req := pkg.CreateImageRequest{ Prompt: `A white cat sitting on a windowsill`, Model: ptr(`dall-e-3`), N: ptr(uint32(1)), Size: ptr(`1024x1024`), } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.ImageGenerate(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result.Data) fmt.Printf("%+v\n", result.Data[0].URL)}Basic image generation with a text prompt
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"model\":\"dall-e-3\",\"n\":1,\"prompt\":\"A white cat sitting on a windowsill\",\"size\":\"1024x1024\"}"; var req = JsonUtil.fromJson(reqJson, CreateImageRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.imageGenerate(req); System.out.println(result.data()); System.out.println(result.data().get(0).url()); } }}Basic image generation with a text prompt
using System;using LiterLlm;
var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.ImageGenerateAsync(new CreateImageRequest { Model = "dall-e-3", N = 1, Prompt = "A white cat sitting on a windowsill", Size = "1024x1024" });Console.WriteLine(result.Data);Console.WriteLine(result.Data[0].Url);Basic image generation with a text prompt
require "liter_llm"result = LiterLlm.image_generate(LiterLlm::CreateImageRequest.new(model: 'dall-e-3', n: 1, prompt: 'A white cat sitting on a windowsill', size: '1024x1024'))puts result.data.inspectputs result.data[0].url.inspectBasic image generation with a text prompt
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\CreateImageRequest;use Liter\Llm\Image;$result = LiterLlm::imageGenerate(new \Liter\Llm\CreateImageRequest(prompt: "A white cat sitting on a windowsill",model: "dall-e-3",n: 1,size: "1024x1024"));var_dump($result->getData());var_dump($result->getData()[0]->url);Basic image generation with a text prompt
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_image_generate_async(client, "{\"model\":\"dall-e-3\",\"n\":1,\"prompt\":\"A white cat sitting on a windowsill\",\"size\":\"1024x1024\"}")IO.inspect(result.data)IO.inspect(Enum.at(result.data, 0).url)Basic image generation with a text prompt
import { WasmCreateImageRequest, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmCreateImageRequest = (() => { const _u0 = WasmCreateImageRequest.default(); _u0.model = "dall-e-3"; _u0.n = 1; _u0.prompt = "A white cat sitting on a windowsill"; _u0.size = "1024x1024"; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.imageGenerate(req); console.log(result.data); console.log(result.data[0].url); } finally { client.free(); }}
void main();Image Parameters
Section titled “Image Parameters”| Parameter | Type | Description |
|---|---|---|
model |
string | Image model (e.g. "openai/dall-e-3") |
prompt |
string | Text description of the image |
n |
int | Number of images to generate |
size |
string | Image size ("1024x1024", "1792x1024", "1024x1792") |
quality |
string | Quality level ("standard" or "hd") |
style |
string | Style ("vivid" or "natural") |
Text-to-Speech
Section titled “Text-to-Speech”Generate audio from text:
Basic text-to-speech generation
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import CreateSpeechRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = CreateSpeechRequest.from_json("{\"input\":\"Hello, world!\",\"model\":\"tts-1\",\"voice\":\"alloy\"}") result = await client.speech(req) print(result)
asyncio.run(main())Basic text-to-speech generation
import { createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.speech({ input: "Hello, world!", model: "tts-1", voice: "alloy" }); console.log(result);}
void main();Basic text-to-speech generation
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"input":"Hello, world!","model":"tts-1","voice":"alloy"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.speech(req).await; println!("{:?}", result);}Basic text-to-speech generation
package main
import ( "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func main() { req := pkg.CreateSpeechRequest{ Model: `tts-1`, Input: `Hello, world!`, Voice: `alloy`, } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.Speech(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result)}Basic text-to-speech generation
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"input\":\"Hello, world!\",\"model\":\"tts-1\",\"voice\":\"alloy\"}"; var req = JsonUtil.fromJson(reqJson, CreateSpeechRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.speech(req); System.out.println(result); } }}Basic text-to-speech generation
using System;using LiterLlm;
var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.SpeechAsync(new CreateSpeechRequest { Input = "Hello, world!", Model = "tts-1", Voice = "alloy" });Console.WriteLine(result);Basic text-to-speech generation
require "liter_llm"result = LiterLlm.speech(LiterLlm::CreateSpeechRequest.new(input: 'Hello, world!', model: 'tts-1', voice: 'alloy'))puts result.inspectBasic text-to-speech generation
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\CreateSpeechRequest;$result = LiterLlm::speech(new \Liter\Llm\CreateSpeechRequest(model: "tts-1",input: "Hello, world!",voice: "alloy"));var_dump($result);Basic text-to-speech generation
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_speech_async(client, "{\"input\":\"Hello, world!\",\"model\":\"tts-1\",\"voice\":\"alloy\"}")IO.inspect(result)Basic text-to-speech generation
import { WasmCreateSpeechRequest, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmCreateSpeechRequest = (() => { const _u0 = WasmCreateSpeechRequest.default(); _u0.input = "Hello, world!"; _u0.model = "tts-1"; _u0.voice = "alloy"; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.speech(req); console.log(result); } finally { client.free(); }}
void main();Speech Parameters
Section titled “Speech Parameters”| Parameter | Type | Description |
|---|---|---|
model |
string | TTS model (e.g. "openai/tts-1") |
input |
string | Text to synthesize |
voice |
string | Voice preset ("alloy", "echo", "fable", "onyx", "nova", "shimmer") |
response_format |
string | Audio format ("mp3", "opus", "aac", "flac") |
speed |
float | Playback speed (0.25-4.0) |
Speech-to-Text
Section titled “Speech-to-Text”Transcribe audio to text:
Basic audio transcription
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import CreateTranscriptionRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = CreateTranscriptionRequest.from_json("{\"file\":\"audio.mp3\",\"model\":\"whisper-1\"}") result = await client.transcribe(req) print(result.text)
asyncio.run(main())Basic audio transcription
import { createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.transcribe({ file: "audio.mp3", model: "whisper-1" }); console.log(result.text);}
void main();Basic audio transcription
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"file":"audio.mp3","model":"whisper-1"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.transcribe(req).await.expect("call failed"); println!("{:?}", result.text);}Basic audio transcription
package main
import ( "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func main() { req := pkg.CreateTranscriptionRequest{ Model: `whisper-1`, File: `audio.mp3`, } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.Transcribe(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result.Text)}Basic audio transcription
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"file\":\"audio.mp3\",\"model\":\"whisper-1\"}"; var req = JsonUtil.fromJson(reqJson, CreateTranscriptionRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.transcribe(req); System.out.println(result.text()); } }}Basic audio transcription
using System;using LiterLlm;
var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.TranscribeAsync(new CreateTranscriptionRequest { File = "audio.mp3", Model = "whisper-1" });Console.WriteLine(result.Text);Basic audio transcription
require "liter_llm"result = LiterLlm.transcribe(LiterLlm::CreateTranscriptionRequest.new(file: 'audio.mp3', model: 'whisper-1'))puts result.text.inspectBasic audio transcription
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\CreateTranscriptionRequest;$result = LiterLlm::transcribe(new \Liter\Llm\CreateTranscriptionRequest(model: "whisper-1",file: "audio.mp3"));var_dump($result->text);Basic audio transcription
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_transcribe_async(client, "{\"file\":\"audio.mp3\",\"model\":\"whisper-1\"}")IO.inspect(result.text)Basic audio transcription
import { WasmCreateTranscriptionRequest, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmCreateTranscriptionRequest = (() => { const _u0 = WasmCreateTranscriptionRequest.default(); _u0.file = "audio.mp3"; _u0.model = "whisper-1"; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.transcribe(req); console.log(result.text); } finally { client.free(); }}
void main();Transcription Parameters
Section titled “Transcription Parameters”| Parameter | Type | Description |
|---|---|---|
model |
string | STT model (e.g. "openai/whisper-1") |
file |
bytes | Audio file data |
language |
string | ISO-639-1 language code |
prompt |
string | Optional context hint |
temperature |
float | Sampling temperature |
response_format |
string | Output format ("json", "text", "srt", "vtt") |
Content Moderation
Section titled “Content Moderation”Classify content for policy violations:
Moderate a single non-flagged input
import asyncioimport osfrom liter_llm import create_clientfrom liter_llm._internal_bindings import ModerationRequest
async def main() -> None: client = create_client(api_key=os.environ["API_KEY"]) req = ModerationRequest.from_json("{\"input\":\"The weather is nice today.\",\"model\":\"omni-moderation-latest\"}") result = await client.moderate(req) print(result.results) print(result.results[0].flagged)
asyncio.run(main())Moderate a single non-flagged input
import { createClient } from "@xberg-io/liter-llm";async function main() { const client = createClient("your-api-key"); const result = await client.moderate({ input: "The weather is nice today.", model: "omni-moderation-latest" }); console.log(result.results); console.log(result.results[0].flagged);}
void main();Moderate a single non-flagged input
use liter_llm::BatchClient;use liter_llm::FileClient;use liter_llm::LlmClient;use liter_llm::ResponseClient;
#[tokio::main]async fn main() { let req_json: serde_json::Value = serde_json::from_str(r#"{"input":"The weather is nice today.","model":"omni-moderation-latest"}"#).unwrap(); let req = serde_json::from_value(req_json).unwrap(); let client = liter_llm::create_client(std::env::var("API_KEY").expect("API_KEY must be set"), None, None, None, None).unwrap(); let result = client.moderate(req).await.expect("call failed"); println!("{:?}", result.results); println!("{:?}", result.results[0].flagged);}Moderate a single non-flagged input
package main
import ( "fmt" pkg "github.com/xberg-io/liter-llm/packages/go/v2")
func ptr[T any](value T) *T { return &value }func main() { req := pkg.ModerationRequest{ Input: pkg.ModerationInput(`The weather is nice today.`), Model: ptr(`omni-moderation-latest`), } client, clientErr := pkg.CreateClient("your-api-key", nil, nil, nil, nil) if clientErr != nil { panic(clientErr) } defer client.Free() result, err := client.Moderate(req) if err != nil { panic(err) } fmt.Printf("%+v\n", result.Results) fmt.Printf("%+v\n", result.Results[0].Flagged)}Moderate a single non-flagged input
import io.xberg.literllm.*;
public final class Example { public static void main(String[] args) throws Exception { var reqJson = "{\"input\":\"The weather is nice today.\",\"model\":\"omni-moderation-latest\"}"; var req = JsonUtil.fromJson(reqJson, ModerationRequest.class); var apiKey = System.getenv("API_KEY"); if (apiKey == null || apiKey.isEmpty()) throw new IllegalStateException("API_KEY must be set"); try (var client = LiterLlm.createClient(apiKey, null, null, null, null)) { var result = client.moderate(req); System.out.println(result.results()); System.out.println(result.results().get(0).flagged()); } }}Moderate a single non-flagged input
using System;using System.Text.Json;using LiterLlm;
var ConfigOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };var apiKey = Environment.GetEnvironmentVariable("API_KEY") ?? throw new InvalidOperationException("API_KEY must be set"); using var client = LiterLlmConverter.CreateClient(apiKey, null, null, null, null);var result = await client.ModerateAsync(new ModerationRequest { Input = JsonSerializer.Deserialize<ModerationInput>("\"The weather is nice today.\"", ConfigOptions)!, Model = "omni-moderation-latest" });Console.WriteLine(result.Results);Console.WriteLine(result.Results[0].Flagged);Moderate a single non-flagged input
require "liter_llm"result = LiterLlm.moderate(LiterLlm::ModerationRequest.new(input: 'The weather is nice today.', model: 'omni-moderation-latest'))puts result.results.inspectputs result.results[0].flagged.inspectModerate a single non-flagged input
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Liter\Llm\LiterLlm;use Liter\Llm\ModerationRequest;$req = \Liter\Llm\ModerationRequest::from_json(json_encode(["input" => "The weather is nice today.", "model" => "omni-moderation-latest"]));$result = LiterLlm::moderate($req);var_dump($result->getResults());var_dump($result->getResults()[0]->flagged);Moderate a single non-flagged input
api_key = System.fetch_env!("API_KEY"){:ok, client} = LiterLlm.create_client(api_key)result = LiterLlm.defaultclient_moderate_async(client, "{\"input\":\"The weather is nice today.\",\"model\":\"omni-moderation-latest\"}")IO.inspect(result.results)IO.inspect(Enum.at(result.results, 0).flagged)Moderate a single non-flagged input
import { WasmModerationRequest, createClient } from "@xberg-io/liter-llm-wasm";async function main() { const req: WasmModerationRequest = (() => { const _u0 = WasmModerationRequest.default(); _u0.input = "The weather is nice today."; _u0.model = "omni-moderation-latest"; return _u0; })(); const client = createClient("your-api-key"); try { const result = await client.moderate(req); console.log(result.results); console.log(result.results[0].flagged); } finally { client.free(); }}
void main();Moderation Parameters
Section titled “Moderation Parameters”| Parameter | Type | Description |
|---|---|---|
input |
string/array | Content to classify |
model |
string | Moderation model (e.g. "openai/omni-moderation-latest") |