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>"
}
}Messages
Anthropic-compatible messages endpoint. Works with the Anthropic SDK, Claude Code, and any Anthropic-compatible client.
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
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 thebase_url and api_key:
- Python
- Node.js
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="")
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: 'YOUR_MODELSLAB_API_KEY',
baseURL: 'https://modelslab.com/api/v7/llm',
});
const message = await client.messages.create({
model: 'Qwen/Qwen2.5-VL-72B-Instruct-together',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Hello!' },
],
});
console.log(message.content[0].text);
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"
Authorizations
API key authentication via x-api-key header
Headers
Anthropic API version
Body
application/json
Model ID to use
Maximum number of tokens to generate
Required range:
x >= 1Array of input messages
Show child attributes
Show child attributes
System prompt
Sampling temperature
Required range:
0 <= x <= 1Nucleus sampling parameter
Required range:
0 <= x <= 1Whether to stream the response
Response
Message response
Was this page helpful?
⌘I

