Generate text with the Liquid API: prompt a model, stream its reply, call tools, and get structured JSON output in a few lines of code.
Generate text with POST /openai/v1/chat/completions. It follows OpenAI’s chat completions API, so the official OpenAI SDKs and most OpenAI-compatible frameworks work with the base URL https://api.liquid.ai/openai/v1.
import osfrom openai import OpenAIclient = OpenAI(api_key=os.environ["LIQUID_API_KEY"], base_url="https://api.liquid.ai/openai/v1")completion = client.chat.completions.create( model="lfm3-1.7b", messages=[ {"role": "system", "content": "You are a concise assistant."}, {"role": "user", "content": "Explain what a liquid neural network is in two sentences."}, ], temperature=0.1, extra_body={"top_k": 50, "repetition_penalty": 1.1},)print(completion.choices[0].message.content)
import OpenAI from "openai";const client = new OpenAI({ apiKey: process.env.LIQUID_API_KEY, baseURL: "https://api.liquid.ai/openai/v1",});const completion = await client.chat.completions.create({ model: "lfm3-1.7b", messages: [ { role: "system", content: "You are a concise assistant." }, { role: "user", content: "Explain what a liquid neural network is in two sentences." }, ], temperature: 0.1, // top_k and repetition_penalty are Liquid extensions to the OpenAI API top_k: 50, repetition_penalty: 1.1,});console.log(completion.choices[0].message.content);
curl https://api.liquid.ai/openai/v1/chat/completions \ -H "Authorization: Bearer $LIQUID_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "lfm3-1.7b", "messages": [ {"role": "system", "content": "You are a concise assistant."}, {"role": "user", "content": "Explain what a liquid neural network is in two sentences."} ], "temperature": 0.1, "top_k": 50, "repetition_penalty": 1.1 }'
messages is the conversation so far. A system message sets the model’s behavior, user messages carry the prompts, and assistant messages carry the model’s earlier replies. To continue a conversation, send the whole history again with the new user message at the end. The API keeps no conversation state between requests.See Chat template and Text generation and prompting for how LFMs read a conversation and how to prompt them.
The API forwards OpenAI’s chat parameters, such as temperature, max_tokens, and stop, to the model. It also forwards top_k and repetition_penalty, which are not part of OpenAI’s API: in the Python SDK, pass them in extra_body.
Set stream to true to receive the reply as server-sent events while the model generates it. Each chunk carries the next piece of text in choices[0].delta.content, and the final usage chunk carries usage.
stream = client.chat.completions.create( model="lfm3-1.7b", messages=[{"role": "user", "content": "Write a haiku about the ocean."}], temperature=0.1, extra_body={"top_k": 50, "repetition_penalty": 1.1}, stream=True,)for chunk in stream: if chunk.choices: print(chunk.choices[0].delta.content or "", end="", flush=True)
const stream = await client.chat.completions.create({ model: "lfm3-1.7b", messages: [{ role: "user", content: "Write a haiku about the ocean." }], temperature: 0.1, // top_k and repetition_penalty are Liquid extensions to the OpenAI API top_k: 50, repetition_penalty: 1.1, stream: true,});for await (const chunk of stream) { process.stdout.write(chunk.choices[0]?.delta?.content ?? "");}
Pass OpenAI-style tools to let the model call functions you define. The model returns tool_calls in its message; run the functions yourself, send their results back as tool messages, and call the model again for its final answer. See Tool use for how LFMs format tool calls.
tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a city.", "parameters": { "type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"], }, }, }]completion = client.chat.completions.create( model="lfm3-1.7b", messages=[{"role": "user", "content": "What's the weather in Boston?"}], tools=tools, temperature=0.1, extra_body={"top_k": 50, "repetition_penalty": 1.1},)print(completion.choices[0].message.tool_calls)
Every response reports usage: prompt_tokens, completion_tokens, and total_tokens, plus cost in USD when the model is priced. Requests count toward your organization’s rate limits.A request body may be up to 4 MB (16 MB for audio models). For images, send URLs rather than inline base64 to stay under the limit.