Skip to main content
POST
Use this API to send text, images, and/or videos and receive generated text back. All supported API capabilities, such as function calling, are documented here. The input and output modality support depends on the model you’re using for inference. This API supports the OpenAI Chat Completions interface. Use a Modular endpoint as the base_url and use a Modular API key when using the OpenAI SDK.

Authorizations

Authorization
string
header
required

Modular Cloud API key. Obtain from the API keys page.

Body

application/json
model
string
required

Model identifier. See the supported models page.

Example:

"google/gemma-4-26b-a4b-it"

messages
object[]
required

The conversation history.

max_tokens
integer

Maximum number of tokens to generate.

temperature
number

Sampling temperature (0–2). Higher values produce more varied output.

Required range: 0 <= x <= 2
stream
boolean

If true, stream partial tokens as server-sent events. Support for tools while streaming is model-dependent; set this to false if you see incomplete or malformed tool-call output.

tools
object[]

List of functions the model may call. See the supported models page for a list of models that support tool use (function calling).

tool_choice

Controls when and how the model calls a tool.

  • none: Disables tool calls.
  • auto (default): Lets the model decide whether to call a tool.
  • required: Forces the model to call at least one tool.
  • A function object: Forces the model to call the named function.

The following example requires the model to call the get_weather function:

Available options:
none,
auto,
required

Response

200 - application/json

Chat completion response.

id
string
required

The unique identifier for the chat completion.

object
string
required

The object type, which is always chat.completion.

model
string
required

The model that generated the completion.

choices
object[]
required

The generated chat completion choices.

usage
object

Token usage for the request.