Skip to main content
POST
/
v1
/
messages
Messages
curl --request POST \
  --url https://modelslab.com/api/v7/llm/v1/messages \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "model": "<string>",
  "max_tokens": 2,
  "messages": [
    {
      "content": "<string>"
    }
  ],
  "system": "<string>",
  "temperature": 1,
  "top_p": 0.5,
  "stream": false
}
'
import requests

url = "https://modelslab.com/api/v7/llm/v1/messages"

payload = {
    "model": "<string>",
    "max_tokens": 2,
    "messages": [{ "content": "<string>" }],
    "system": "<string>",
    "temperature": 1,
    "top_p": 0.5,
    "stream": False
}
headers = {
    "x-api-key": "<api-key>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    model: '<string>',
    max_tokens: 2,
    messages: [{content: '<string>'}],
    system: '<string>',
    temperature: 1,
    top_p: 0.5,
    stream: false
  })
};

fetch('https://modelslab.com/api/v7/llm/v1/messages', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://modelslab.com/api/v7/llm/v1/messages",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'model' => '<string>',
    'max_tokens' => 2,
    'messages' => [
        [
                'content' => '<string>'
        ]
    ],
    'system' => '<string>',
    'temperature' => 1,
    'top_p' => 0.5,
    'stream' => false
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json",
    "x-api-key: <api-key>"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://modelslab.com/api/v7/llm/v1/messages"

	payload := strings.NewReader("{\n  \"model\": \"<string>\",\n  \"max_tokens\": 2,\n  \"messages\": [\n    {\n      \"content\": \"<string>\"\n    }\n  ],\n  \"system\": \"<string>\",\n  \"temperature\": 1,\n  \"top_p\": 0.5,\n  \"stream\": false\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<api-key>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://modelslab.com/api/v7/llm/v1/messages")
  .header("x-api-key", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"<string>\",\n  \"max_tokens\": 2,\n  \"messages\": [\n    {\n      \"content\": \"<string>\"\n    }\n  ],\n  \"system\": \"<string>\",\n  \"temperature\": 1,\n  \"top_p\": 0.5,\n  \"stream\": false\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://modelslab.com/api/v7/llm/v1/messages")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model\": \"<string>\",\n  \"max_tokens\": 2,\n  \"messages\": [\n    {\n      \"content\": \"<string>\"\n    }\n  ],\n  \"system\": \"<string>\",\n  \"temperature\": 1,\n  \"top_p\": 0.5,\n  \"stream\": false\n}"

response = http.request(request)
puts response.read_body
{
  "id": "<string>",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "<string>"
    }
  ],
  "model": "<string>",
  "usage": {
    "input_tokens": 123,
    "output_tokens": 123
  }
}
{
  "error": {
    "message": "<string>",
    "type": "<string>",
    "code": "<string>"
  }
}

Request

POST https://modelslab.com/api/v7/llm/v1/messages
Pass your API key in the x-api-key header or as a Bearer token.
curl -X POST https://modelslab.com/api/v7/llm/v1/messages \
  -H "x-api-key: $MODELSLAB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "Qwen/Qwen2.5-VL-72B-Instruct-together",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "What is the capital of France?"}
    ]
  }'

Body

{
  "model": "Qwen/Qwen2.5-VL-72B-Instruct-together",
  "max_tokens": 1024,
  "messages": [
    {"role": "user", "content": "What is the capital of France?"}
  ],
  "system": "You are a helpful assistant.",
  "temperature": 0.7,
  "top_p": 1,
  "stream": false
}

Response

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "The capital of France is Paris."
    }
  ],
  "model": "Qwen/Qwen2.5-VL-72B-Instruct-together",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 15,
    "output_tokens": 8
  }
}

Streaming

Set "stream": true to receive Server-Sent Events:
curl -X POST https://modelslab.com/api/v7/llm/v1/messages \
  -H "x-api-key: $MODELSLAB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "Qwen/Qwen2.5-VL-72B-Instruct-together",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Write a haiku"}],
    "stream": true
  }'

Anthropic SDK

This endpoint is fully compatible with the Anthropic SDK. Just change the base_url and api_key:
from anthropic import Anthropic

client = Anthropic(
    api_key="YOUR_MODELSLAB_API_KEY",
    base_url="https://modelslab.com/api/v7/llm",
)

# Non-streaming
message = client.messages.create(
    model="Qwen/Qwen2.5-VL-72B-Instruct-together",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain quantum computing"}
    ],
)
print(message.content[0].text)

# Streaming
with client.messages.stream(
    model="Qwen/Qwen2.5-VL-72B-Instruct-together",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a story"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")

Using with Claude Code

You can use ModelsLab’s LLM API as a backend for Claude Code, Anthropic’s CLI coding assistant:
ANTHROPIC_BASE_URL="https://modelslab.com/api/v7/llm" \
ANTHROPIC_AUTH_TOKEN="YOUR_MODELSLAB_API_KEY" \
claude --model "Qwen/Qwen2.5-VL-72B-Instruct-together"
This lets you use any of ModelsLab’s 200+ LLM models as the backend for Claude Code’s agentic coding capabilities.

Authorizations

x-api-key
string
header
required

API key authentication via x-api-key header

Headers

anthropic-version
string
default:2023-06-01

Anthropic API version

Body

application/json
model
string
required

Model ID to use

max_tokens
integer
required

Maximum number of tokens to generate

Required range: x >= 1
messages
object[]
required

Array of input messages

system
string

System prompt

temperature
number
default:1

Sampling temperature

Required range: 0 <= x <= 1
top_p
number

Nucleus sampling parameter

Required range: 0 <= x <= 1
stream
boolean
default:false

Whether to stream the response

Response

Message response

id
string

Unique message ID

type
enum<string>
Available options:
message
role
enum<string>
Available options:
assistant
content
object[]
model
string
stop_reason
enum<string>
Available options:
end_turn,
max_tokens,
stop_sequence
usage
object