AI Inference
The AI Inference resource is the OpenAI-compatible gateway for chat completions, text completions, embeddings, and audio. Reference a model by its vendor id; the gateway resolves the provider key and routes the call.
Access it as client.ai.inference on a Strongly client, or the same path on AsyncStrongly with await. All methods exist on both with identical signatures.
Methods
All methods
cancel_generation
cancel_generation(*, job_id: str) -> GenerationJob
Cancel an async generation job.
chat_completion
chat_completion(*, model: str, messages: Sequence[Union[Dict[str, Any], ChatMessage]], stream: bool = False, max_tokens: Optional[int] = None, temperature: float = 0.7, top_p: float = 1.0, stop: Optional[Union[str, List[str]]] = None, **kwargs) -> Union[ChatCompletion, Iterator[StreamChunk]]
Send a chat completion request.
Args: model: The model ID to use. messages: List of chat messages. stream: If True, return an iterator of StreamChunk objects. max_tokens: Maximum tokens to generate. temperature: Sampling temperature. top_p: Nucleus sampling parameter. stop: Stop sequence(s). **kwargs: Additional parameters forwarded to the API.
Returns: ChatCompletion if stream=False, Iterator[StreamChunk] if stream=True.
completion
completion(*, model: str, prompt: str, stream: bool = False, max_tokens: Optional[int] = None, temperature: float = 0.7, **kwargs) -> Union[Completion, Iterator[StreamChunk]]
Send a text completion request.
Args: model: The model ID to use. prompt: The text prompt. stream: If True, return an iterator of StreamChunk objects. max_tokens: Maximum tokens to generate. temperature: Sampling temperature. **kwargs: Additional parameters forwarded to the API.
Returns: Completion if stream=False, Iterator[StreamChunk] if stream=True.
embedding
embedding(*, model: str, input: Union[str, List[str]], **kwargs) -> EmbeddingResponse
Create embeddings.
Args: model: The model ID to use. input: Text or list of texts to embed. **kwargs: Additional parameters forwarded to the API.
generate
generate(*, model: str, prompt: str, type: Optional[str] = None, **kwargs) -> Dict[str, Any]
Submit a generic generation job (umbrella endpoint).
Equivalent to the type-specific /ai/generations/{type} POSTs but the gateway
dispatches by type.
Args:
model: The generation model ID.
prompt: The text prompt.
type: Generation type (image, video, or music).
**kwargs: Additional generation parameters forwarded to the gateway.
generation_status
generation_status(*, job_id: str) -> GenerationJob
Check the status of an async generation job.
image_generation
image_generation(*, model: str, prompt: str, n: int = 1, size: str = "1024x1024", quality: str = "standard", response_format: str = "url", **kwargs) -> ImageGenerationResponse
Generate images from a text prompt.
list_speech_voices
list_speech_voices() -> Dict[str, Any]
List available TTS voices across providers.
moderation
moderation(*, model: str, input: Union[str, List[str]], **kwargs) -> ModerationResponse
Check text for content policy violations.
music_generation
music_generation(*, model: str, prompt: str, duration: int = 30, **kwargs) -> GenerationJob
Submit a music generation job (async).
rerank
rerank(*, model: str, query: str, documents: List[Union[str, Dict[str, Any]]], top_n: Optional[int] = None, return_documents: bool = True, **kwargs) -> RerankResponse
Rerank documents by relevance to a query.
speech
speech(*, model: str, input: str, voice: str = "alloy", response_format: str = "mp3", speed: float = 1.0, **kwargs) -> SpeechResponse
Generate speech audio from text (TTS).
transcription
transcription(*, model: str, file: Any, filename: str = "audio.mp3", language: Optional[str] = None, prompt: Optional[str] = None, response_format: str = "json", temperature: float = 0.0, **kwargs) -> TranscriptionResponse
Transcribe audio to text (STT).
translation
translation(*, model: str, file: Any, filename: str = "audio.mp3", **kwargs) -> TranscriptionResponse
Translate audio to English text (STT translation).
video_generation
video_generation(*, model: str, prompt: str, duration: int = 5, resolution: str = "1080p", **kwargs) -> GenerationJob
Submit a video generation job (async).