Skip to content

Create Messages

This endpoint is compatible with Anthropic’s Claude Messages API format. Send a structured list of input messages with text and/or image content if the model supports images. The model will generate the next message in the conversation.

The Messages API can be used for either single queries or stateless multi-turn conversations.

POST https://api.relax.ai/v1/messages

from anthropic import Anthropic
client = Anthropic(
api_key = RELAX_API_KEY,
base_url = 'https://api.relax.ai/v1/',
)
message = client.messages.create(
model="GPT-OSS-120b",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is the capital of the UK?"}
]
)
print(message.content)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: RELAX_API_KEY,
baseURL: 'https://api.relax.ai/v1/'
});
const message = await anthropic.messages.create({
model: "GPT-OSS-120b",
max_tokens: 1024,
messages: [
{ role: "user", content: "What is the capital of the UK?" }
]
});
console.log(message.content);
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("RELAX_API_KEY"),
option.WithBaseURL("https://api.relax.ai/v1/"),
)
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: "GPT-OSS-120b",
MaxTokens: 1024,
Messages: []anthropic.MessageParam{{
Role: anthropic.MessageParamRoleUser,
Content: []anthropic.ContentBlockParamUnion{{
OfText: &anthropic.TextBlockParam{
Text: "What is the capital of the UK?",
},
}},
}},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", message.Content)
}
Terminal window
curl https://api.relax.ai/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $RELAX_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "GPT-OSS-120b",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "What is the capital of the UK?"}
]
}'

Returns a Message object.


Message Response
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"model": "GPT-OSS-120b",
"content": [
{
"type": "text",
"text": "The capital of the United Kingdom is London."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 16,
"output_tokens": 15
}
}

The following parameters can be included in the request body:


ParameterTypeRequiredDescription
modelstringYesThe model that will complete your prompt. See models for available options.
messagesarray of objectsYesInput messages. An array of message objects with role and content fields. The role can be user or assistant. Messages must alternate between user and assistant roles.
max_tokensintegerYesThe maximum number of tokens to generate before stopping. Different models have different maximum values.
systemstring or array of objectsNoSystem prompt. A system prompt is a way of providing context and instructions to the model, such as specifying a particular goal or role.
temperaturefloat (0.0 to 1.0)NoAmount of randomness injected into the response. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical/multiple choice, and closer to 1.0 for creative and generative tasks. Default: 1.0
top_pfloat (0.0 to 1.0)NoUse nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. Recommended to use temperature or top_p but not both.
top_kintegerNoOnly sample from the top K options for each subsequent token. Used to remove “long tail” low probability responses.
stop_sequencesarray of stringsNoCustom text sequences that will cause the model to stop generating. Up to 5 sequences supported.
streambooleanNoWhether to incrementally stream the response using server-sent events (SSE). Default: false
toolsarray of objectsNoDefinitions of tools that the model may use. See tool calling for more details.

The Messages API supports streaming responses using Server-Sent Events (SSE). Streaming is useful when you want to display partial results to users as they’re generated.

from anthropic import Anthropic
client = Anthropic(
api_key = RELAX_API_KEY,
base_url = 'https://api.relax.ai/v1/',
)
with client.messages.stream(
model="GPT-OSS-120b",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is the capital of the UK?"}
]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: RELAX_API_KEY,
baseURL: 'https://api.relax.ai/v1/'
});
const stream = await anthropic.messages.stream({
model: "GPT-OSS-120b",
max_tokens: 1024,
messages: [
{ role: "user", content: "What is the capital of the UK?" }
]
});
for await (const chunk of stream) {
if (chunk.type === 'content_block_delta' &&
chunk.delta.type === 'text_delta') {
process.stdout.write(chunk.delta.text);
}
}
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("RELAX_API_KEY"),
option.WithBaseURL("https://api.relax.ai/v1/"),
)
stream := client.Messages.NewStreaming(context.TODO(), anthropic.MessageNewParams{
Model: "GPT-OSS-120b",
MaxTokens: 1024,
Messages: []anthropic.MessageParam{{
Role: anthropic.MessageParamRoleUser,
Content: []anthropic.ContentBlockParamUnion{{
OfText: &anthropic.TextBlockParam{
Text: "What is the capital of the UK?",
},
}},
}},
})
for stream.Next() {
event := stream.Current()
if event.Delta.Text != "" {
fmt.Print(event.Delta.Text)
}
}
if err := stream.Err(); err != nil {
panic(err.Error())
}
}
Terminal window
curl https://api.relax.ai/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $RELAX_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "GPT-OSS-120b",
"max_tokens": 1024,
"stream": true,
"messages": [
{"role": "user", "content": "What is the capital of the UK?"}
]
}'

The Messages API supports tool use (also known as function calling), allowing the model to request that you call external tools and APIs to complete tasks.

from anthropic import Anthropic
client = Anthropic(
api_key=RELAX_API_KEY,
base_url='https://api.relax.ai/v1/',
)
tools = [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature"
}
},
"required": ["location"]
}
}
]
message = client.messages.create(
model="GPT-OSS-120b",
max_tokens=1024,
tools=tools,
messages=[
{"role": "user", "content": "What's the weather like in London?"}
]
)
print(message.content)
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: RELAX_API_KEY,
baseURL: 'https://api.relax.ai/v1/'
});
const tools = [
{
name: "get_weather",
description: "Get the current weather in a given location",
input_schema: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA"
},
unit: {
type: "string",
enum: ["celsius", "fahrenheit"],
description: "The unit of temperature"
}
},
required: ["location"]
}
}
];
const message = await anthropic.messages.create({
model: "GPT-OSS-120b",
max_tokens: 1024,
tools: tools,
messages: [
{ role: "user", content: "What's the weather like in London?" }
]
});
console.log(message.content);
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/invopop/jsonschema"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("RELAX_API_KEY"),
option.WithBaseURL("https://api.relax.ai/v1/"),
)
messages := []anthropic.MessageParam{
anthropic.NewUserMessage(
anthropic.NewTextBlock("What's the weather like in London?"),
),
}
toolParams := []anthropic.ToolParam{{
Name: "get_weather",
Description: anthropic.String("Get the current weather in a given location"),
InputSchema: GetWeatherInputSchema,
}}
tools := make([]anthropic.ToolUnionParam, len(toolParams))
for i, toolParam := range toolParams {
tools[i] = anthropic.ToolUnionParam{OfTool: &toolParam}
}
message, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
Model: "GPT-OSS-120b",
MaxTokens: 1024,
Messages: messages,
Tools: tools,
})
if err != nil {
panic(err.Error())
}
for _, block := range message.Content {
switch block := block.AsAny().(type) {
case anthropic.TextBlock:
fmt.Println(block.Text)
case anthropic.ToolUseBlock:
inputJSON, _ := json.Marshal(block.Input)
fmt.Printf("%s: %s\n", block.Name, string(inputJSON))
}
}
}
type GetWeatherInput struct {
Location string \`json:"location" jsonschema_description:"The city and state, e.g. San Francisco, CA"\`
Unit string \`json:"unit" jsonschema_description:"The unit of temperature"\`
}
var GetWeatherInputSchema = GenerateSchema[GetWeatherInput]()
func GenerateSchema[T any]() anthropic.ToolInputSchemaParam {
reflector := jsonschema.Reflector{
AllowAdditionalProperties: false,
DoNotReference: true,
}
var v T
schema := reflector.Reflect(v)
return anthropic.ToolInputSchemaParam{
Properties: schema.Properties,
}
}
Terminal window
curl https://api.relax.ai/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $RELAX_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "GPT-OSS-120b",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
],
"messages": [
{"role": "user", "content": "What is the weather in London?"}
]
}'