Prerequisites
Before you get started, you need:- Authentication: API keys sent with Bearer authentication
- curl or similar: A tool to make API requests
List available models
Most API requests require you to pass a modelid. To get all available models and their ids:
id malibu.
Chat prompt example
To generate completions from a model, you need the modelid and your prompt formatted as content inside messages with the user role:
model(required): Modelidto use.messages(required): An array of messages representing the conversation.max_completion_tokens(optional): The maximum number of tokens to generate in the completion.stop(optional): An array of sequences where the API stops generating further tokens.temperature(optional): What sampling temperature to use, between 0 and 2. Higher values like 0.8 make the output more random, while lower values like 0.2 make it more focused and deterministic.stream(optional): Response format. A stream of a series of events or a single JSON object.
stream to true. This is useful for real-time applications.
Chat prompt example with expanded context
Optionally, you can add more context to a query. This is useful when you want to give the model information it does not have. Refer to the Prompting guide for further guidance. Consider the following query:Extend models with tools
You can extend your model’s capabilities by providing tools (functions) that the model can call during conversations. This enables the model to perform actions like retrieving real-time data, calculations, or interacting with external systems. To use tools, include atools array in your request and define the functions the model can call:
tool_calls array in the assistant message.
Response: