Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.2.0+

AI: Simple Stateless Query

See more AI Examples

Demonstrates the simplest stateless query: asking an AI to "Say Hello". This query is standalone and not part of a conversation.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local ai = chilkat.Ai.new()

-- The provider can be "openai", "google", "claude", "deepseek", "xai", or "perplexity".
-- Support for additional providers will be added in future versions of Chilkat.
ai.provider = "openai"

-- Use your provider's API key.
ai.api_key = "MY_API_KEY"

-- Choose a model.
ai.model = "gpt-5.6-terra"

-- Add a text input.
ai:input_add_text("Say Hello.")

-- Ask the AI for text output.
local success = ai:ask("text")
if not success then
    print(ai.last_error_text)
    return
end

-- Get the text response.
local sbResponse = chilkat.StringBuilder.new()
ai:get_output_text_sb(sbResponse)
print(sbResponse:get_as_string())

-- Sample output:
-- Hello! How can I assist you today?

-- -------------------------------------------------------------
-- The response is in markdown format.
-- Also see Markdown to HTML Conversion Examples.
-- -------------------------------------------------------------