Generator Creation
model: The model to use for generationout: Pointer to store the created generator params
NULL on success, or OgaResult* containing error message on failureparams: The generator params to destroy
model: The model to use for generationparams: The parameters to use for generationout: Pointer to store the created generator
NULL on success, or OgaResult* containing error message on failureExample:generator: The generator to destroy
Generator Parameters
Search Parameters
params: The generator params to modifyname: The parameter name (e.g., “max_length”, “temperature”, “top_p”, “top_k”)value: The numerical value to set
NULL on success, or OgaResult* containing error message on failureExample:params: The generator params to modifyname: The parameter namevalue: The boolean value to set
NULL on success, or OgaResult* containing error message on failureparams: The generator params to queryname: The parameter namevalue: Pointer to store the parameter value
NULL on success, or OgaResult* containing error message on failureparams: The generator params to queryname: The parameter namevalue: Pointer to store the parameter value
NULL on success, or OgaResult* containing error message on failureGuided Generation
params: The generator params to modifytype: The guidance type (“json_schema”, “regex”, or “lark_grammar”)data: The guidance specificationenable_ff_tokens: Whether to enable force-forward tokens (only valid with batch_size=1 and beam_size=1)
NULL on success, or OgaResult* containing error message on failureExample:Input Management
generator: The generator to add tokens top_sequences: The input token sequences
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to add tokens toinput_ids: Array of token IDsinput_ids_count: Number of tokens (batch_size × sequence_length)
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to query
generator: The generator to set inputs onname: Name of the model input (must match the model’s input name)tensor: The tensor containing the input data
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to set inputs onnamed_tensors: Collection of named tensors
NULL on success, or OgaResult* containing error message on failureGeneration Loop
generator: The generator to advance
NULL on success, or OgaResult* containing error message on failureExample:generator: The generator to queryout: Pointer to store the token array (valid until next generator call)out_count: Pointer to store the number of tokens
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to check
true if generation is complete, false otherwisegenerator: The generator to check
true if session is terminated, false otherwiseSequence Access
generator: The generator to queryindex: The sequence index
generator: The generator to queryindex: The sequence index
Logits Access and Modification
generator: The generator to get logits fromout: Pointer to store the logits tensor
NULL on success, or OgaResult* containing error message on failureNote: The returned tensor must be destroyed with OgaDestroyTensor()generator: The generator to set logits ontensor: The logits tensor (must have same shape asGetLogitsoutput)
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to queryname: Name of the input tensorout: Pointer to store the input tensor
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to queryname: Name of the output tensorout: Pointer to store the output tensor
NULL on success, or OgaResult* containing error message on failureAdvanced Features
generator: The generator to rewindnew_length: The desired token length after rewinding
NULL on success, or OgaResult* containing error message on failuregenerator: The generator to configurekey: The runtime option namevalue: The runtime option value
NULL on success, or OgaResult* containing error message on failureComplete Generation Example
Streaming Generation Example
See Also
C API Overview
Learn about memory management and error handling
Model Functions
Create and configure models