# Messages (Anthropic)

URL: https://docs.unli.dev/messages

> Create a message using Anthropic Claude Messages API

## OpenAPI specification

```json
{
  "openapi": "3.2.0",
  "info": {
    "title": "UNLI API",
    "version": "1.0.0",
    "description": "OpenAPI spec for UNLI API Anthropic Messages endpoint."
  },
  "servers": [
    {
      "url": "https://api.unli.dev/v1",
      "description": "UNLI API"
    }
  ],
  "paths": {
    "/messages": {
      "post": {
        "operationId": "createMessage",
        "summary": "Create a message",
        "description": "Send a structured list of input messages with text and/or image content, and the model will generate the next message in the conversation. Compatible with Anthropic Claude Messages API format.",
        "tags": [
          "Anthropic Messages"
        ],
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "anthropic-version",
            "in": "header",
            "required": false,
            "description": "Anthropic API version header (e.g. 2023-06-01)",
            "schema": {
              "type": "string",
              "default": "2023-06-01"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMessageRequest"
              },
              "examples": {
                "default": {
                  "summary": "Basic text message request",
                  "value": {
                    "model": "unli-auto",
                    "max_tokens": 1024,
                    "messages": [
                      {
                        "role": "user",
                        "content": "Hello, Claude!"
                      }
                    ]
                  }
                },
                "withSystemAndImages": {
                  "summary": "Request with system prompt and image",
                  "value": {
                    "model": "unli-auto",
                    "max_tokens": 1024,
                    "system": "You are an expert image analyst.",
                    "messages": [
                      {
                        "role": "user",
                        "content": [
                          {
                            "type": "image",
                            "source": {
                              "type": "base64",
                              "media_type": "image/jpeg",
                              "data": "/9j/4AAQSkZJRg..."
                            }
                          },
                          {
                            "type": "text",
                            "text": "What is depicted in this image?"
                          }
                        ]
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message response generated successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResponse"
                },
                "examples": {
                  "default": {
                    "summary": "Example response",
                    "value": {
                      "id": "msg_01XFDUDYJgAACgrFtApKcNx3",
                      "type": "message",
                      "role": "assistant",
                      "content": [
                        {
                          "type": "text",
                          "text": "Hello! How can I assist you today?"
                        }
                      ],
                      "model": "unli-auto",
                      "stop_reason": "end_turn",
                      "stop_sequence": null,
                      "usage": {
                        "input_tokens": 10,
                        "output_tokens": 12
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Bearer token authentication using API keys"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Anthropic x-api-key header authentication"
      }
    },
    "schemas": {
      "CreateMessageRequest": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "description": "The model that will complete your prompt. Use 'unli-auto' for automatic routing.",
            "default": "unli-auto"
          },
          "messages": {
            "type": "array",
            "description": "Input messages. Our models are trained to operate on alternating 'user' and 'assistant' conversational turns.",
            "items": {
              "$ref": "#/components/schemas/AnthropicMessage"
            }
          },
          "max_tokens": {
            "type": "integer",
            "description": "The maximum number of tokens to generate before stopping.",
            "example": 1024
          },
          "system": {
            "oneOf": [
              {
                "type": "string",
                "description": "System prompt providing context and behavior instructions."
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TextBlock"
                },
                "description": "System prompt as an array of content blocks."
              }
            ],
            "description": "System prompt to guide model behavior."
          },
          "metadata": {
            "type": "object",
            "description": "An object describing metadata about the request.",
            "properties": {
              "user_id": {
                "type": "string",
                "description": "An external identifier for the user."
              }
            }
          },
          "stop_sequences": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Custom text sequences that will cause the model to stop generating."
          },
          "stream": {
            "type": "boolean",
            "description": "Whether to incrementally stream the response using server-sent events.",
            "default": false
          },
          "temperature": {
            "type": "number",
            "description": "Amount of randomness injected into the response. Ranges from 0.0 to 1.0.",
            "minimum": 0,
            "maximum": 1,
            "default": 1
          },
          "top_p": {
            "type": "number",
            "description": "Use nucleus sampling. In nucleus sampling, we compute the cumulative distribution over all options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p.",
            "minimum": 0,
            "maximum": 1
          },
          "top_k": {
            "type": "integer",
            "description": "Only sample from the top K options for each subsequent token.",
            "minimum": 1
          },
          "tools": {
            "type": "array",
            "description": "Definitions of tools that the model may use.",
            "items": {
              "$ref": "#/components/schemas/Tool"
            }
          },
          "tool_choice": {
            "type": "object",
            "description": "How the model should use the provided tools.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "auto",
                  "any",
                  "tool"
                ],
                "description": "The tool choice mode."
              },
              "name": {
                "type": "string",
                "description": "The name of the tool to use (when type is 'tool')."
              }
            },
            "required": [
              "type"
            ]
          }
        },
        "required": [
          "model",
          "messages",
          "max_tokens"
        ]
      },
      "AnthropicMessage": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant"
            ],
            "description": "The role of the message author."
          },
          "content": {
            "oneOf": [
              {
                "type": "string",
                "description": "Text content of the message."
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ContentBlock"
                },
                "description": "Array of content blocks (text, image, tool_use, tool_result)."
              }
            ],
            "description": "The content of the message."
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "ContentBlock": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/TextBlock"
          },
          {
            "$ref": "#/components/schemas/ImageBlock"
          },
          {
            "$ref": "#/components/schemas/ToolUseBlock"
          },
          {
            "$ref": "#/components/schemas/ToolResultBlock"
          }
        ]
      },
      "TextBlock": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "text"
            ]
          },
          "text": {
            "type": "string",
            "description": "The text content."
          }
        },
        "required": [
          "type",
          "text"
        ]
      },
      "ImageBlock": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "image"
            ]
          },
          "source": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "base64"
                ]
              },
              "media_type": {
                "type": "string",
                "enum": [
                  "image/jpeg",
                  "image/png",
                  "image/gif",
                  "image/webp"
                ]
              },
              "data": {
                "type": "string",
                "description": "Base64-encoded image data."
              }
            },
            "required": [
              "type",
              "media_type",
              "data"
            ]
          }
        },
        "required": [
          "type",
          "source"
        ]
      },
      "ToolUseBlock": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "tool_use"
            ]
          },
          "id": {
            "type": "string",
            "description": "Unique identifier for this tool use invocation."
          },
          "name": {
            "type": "string",
            "description": "The name of the tool to be called."
          },
          "input": {
            "type": "object",
            "description": "The arguments to pass to the tool."
          }
        },
        "required": [
          "type",
          "id",
          "name",
          "input"
        ]
      },
      "ToolResultBlock": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "tool_result"
            ]
          },
          "tool_use_id": {
            "type": "string",
            "description": "The id of the tool_use block this result corresponds to."
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TextBlock"
                }
              }
            ],
            "description": "The result content of the tool execution."
          },
          "is_error": {
            "type": "boolean",
            "description": "Whether the tool execution resulted in an error."
          }
        },
        "required": [
          "type",
          "tool_use_id",
          "content"
        ]
      },
      "Tool": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of the function/tool."
          },
          "description": {
            "type": "string",
            "description": "A description of what the tool does."
          },
          "input_schema": {
            "type": "object",
            "description": "JSON Schema for the tool input arguments."
          }
        },
        "required": [
          "name",
          "input_schema"
        ]
      },
      "MessageResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique object identifier."
          },
          "type": {
            "type": "string",
            "enum": [
              "message"
            ],
            "description": "Object type, always 'message'."
          },
          "role": {
            "type": "string",
            "enum": [
              "assistant"
            ],
            "description": "Conversational role of the generated message, always 'assistant'."
          },
          "content": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/TextBlock"
                },
                {
                  "$ref": "#/components/schemas/ToolUseBlock"
                }
              ]
            },
            "description": "Content generated by the model."
          },
          "model": {
            "type": "string",
            "description": "The model that handled the request."
          },
          "stop_reason": {
            "type": "string",
            "enum": [
              "end_turn",
              "max_tokens",
              "stop_sequence",
              "tool_use"
            ],
            "description": "The reason that the model stopped generating."
          },
          "stop_sequence": {
            "type": "string",
            "nullable": true,
            "description": "Which custom stop sequence was generated, if any."
          },
          "usage": {
            "$ref": "#/components/schemas/MessageUsage"
          }
        },
        "required": [
          "id",
          "type",
          "role",
          "content",
          "model",
          "stop_reason",
          "usage"
        ]
      },
      "MessageUsage": {
        "type": "object",
        "properties": {
          "input_tokens": {
            "type": "integer",
            "description": "The number of input tokens which were used."
          },
          "output_tokens": {
            "type": "integer",
            "description": "The number of output tokens which were used."
          },
          "cache_creation_input_tokens": {
            "type": "integer",
            "description": "The number of input tokens used to create the cache entry."
          },
          "cache_read_input_tokens": {
            "type": "integer",
            "description": "The number of input tokens read from the cache."
          }
        },
        "required": [
          "input_tokens",
          "output_tokens"
        ]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "error"
            ]
          },
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "description": "Error type (e.g. invalid_request_error, authentication_error, rate_limit_error)."
              },
              "message": {
                "type": "string",
                "description": "Error message explanation."
              }
            },
            "required": [
              "type",
              "message"
            ]
          }
        },
        "required": [
          "type",
          "error"
        ]
      }
    }
  }
}
```
