Skip to Content
API CallText GenerationClaude (Anthropic) compatibility description

Claude (Anthropic) Compatibility Guide

Important Note: We provide API services compatible with Anthropic standards. Therefore, we strongly recommend directly referring to the official Anthropic API documentation to obtain the most comprehensive, up-to-date parameter details and examples. The following is an overview of the simplified interface, focusing on core fields and usage instructions.

Overview

UModelverse platform provides a Messages interface compatible with the Anthropic Claude API, allowing developers to directly invoke models on Modelverse using the Anthropic SDK or other supported tools.

  • Request Method: POST
  • Endpoint: https://api.umodelverse.ai/v1/messages
  • Authentication: Use API key, pass through x-api-key: {api_key} or Authorization: Bearer {api_key}

Note: The /v1/messages endpoint only supports the Claude series models. For other models (such as GPT, Gemini, DeepSeek, etc.), use the OpenAI-compatible /v1/chat/completions endpoint. Although Claude and OpenAI both use /v1/models to obtain a list of models, the call interfaces are different.

Key Core Fields

Request Fields

FieldTypeRequiredDefaultDescription
modelstringYesNoneModel ID, such as claude-sonnet-4-5-20250929. Specifies the model for generating responses.
messagesarrayYesNoneList of conversation messages. Each message includes role (user/assistant) and content (text/image).
max_tokensintegerYesNoneMaximum number of tokens to generate. Controls the response length to prevent overly lengthy outputs.
systemstring/arrayNoNoneSystem prompts. Defines model behavior and roles.
temperaturenumberNo1.0Sampling temperature (0 to 1). Controls randomness, with higher values being more creative and lower values being more deterministic.
top_pnumberNoNoneNucleus sampling (0 to 1). Controls diversity.
top_kintegerNoNoneTop-K sampling. Samples only from the top K tokens with the highest probabilities.
stop_sequencesarrayNoNoneList of stop sequences. Stops generation upon reaching these sequences.
streambooleanNofalseWhether to stream responses. Returns content incrementally in real-time.
metadataobjectNoNoneMetadata object, which can include user_id for tracking.
toolsarrayNoNoneList of available tools. Enables function calling features.
tool_choiceobjectNoautoTool selection strategy. For example, {"type": "auto"} lets the model decide to invoke tools.

Response Fields

FieldTypeDescription
idstringResponse ID. Uniquely identifies this completion.
typestringObject type: message.
rolestringRole: assistant.
contentarrayList of content blocks. Each block contains type and corresponding content (such as text).
modelstringThe model ID used.
stop_reasonstringStop reason: end_turn, max_tokens, stop_sequence, tool_use.
stop_sequencestringSequence that triggered the stop (if applicable).
usageobjectUsage statistics. Includes input_tokens and output_tokens.

Quick Start

Install Anthropic SDK

pip install anthropic

Sample Code

** Python **

import anthropic client = anthropic.Anthropic( api_key="<MODELVERSE_API_KEY>", base_url="https://api.umodelverse.ai" ) message = client.messages.create( model="claude-sonnet-4-5-20250929", max_tokens=1024, messages=[ {"role": "user", "content": "Hello, how are you?"} ] ) print(message.content[0].text)

** Python Streaming **

import anthropic client = anthropic.Anthropic( api_key="<MODELVERSE_API_KEY>", base_url="https://api.umodelverse.ai" ) with client.messages.stream( model="claude-sonnet-4-5-20250929", max_tokens=1024, messages=[ {"role": "user", "content": "Write a short story about AI."} ] ) as stream: for text in stream.text_stream: print(text, end="", flush=True)

** curl **

curl https://api.umodelverse.ai/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: $MODELVERSE_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "claude-sonnet-4-5-20250929", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello, how are you?"} ] }'

** curl Streaming **

curl https://api.umodelverse.ai/v1/messages \ -H "Content-Type: application/json" \ -H "x-api-key: $MODELVERSE_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -d '{ "model": "claude-sonnet-4-5-20250929", "max_tokens": 1024, "stream": true, "messages": [ {"role": "user", "content": "Hello, how are you?"} ] }'

Multimodal Support

Claude-compatible interfaces support image input, which can be delivered via base64 encoding or URL:

Using URL

import anthropic client = anthropic.Anthropic( api_key="<MODELVERSE_API_KEY>", base_url="https://api.umodelverse.ai" ) # Using URL to pass image message = client.messages.create( model="claude-sonnet-4-5-20250929", max_tokens=1024, messages=[ { "role": "user", "content": [ { "type": "image", "source": { "type": "url", "url": "https://umodelverse-inference.cn-wlcb.ufileos.com/ucloud-maxcot.jpg" } }, { "type": "text", "text": "What's in this image?" } ] } ] ) print(message.content[0].text)

Using base64 Encoding

import anthropic import base64 client = anthropic.Anthropic( api_key="<MODELVERSE_API_KEY>", base_url="https://api.umodelverse.ai" ) # Using base64 to encode image with open("image.png", "rb") as f: image_data = base64.standard_b64encode(f.read()).decode("utf-8") message = client.messages.create( model="claude-sonnet-4-5-20250929", max_tokens=1024, messages=[ { "role": "user", "content": [ { "type": "image", "source": { "type": "base64", "media_type": "image/png", "data": image_data } }, { "type": "text", "text": "What's in this image?" } ] } ] ) print(message.content[0].text)

Tool Calling (Function Calling)

import anthropic client = anthropic.Anthropic( api_key="<MODELVERSE_API_KEY>", base_url="https://api.umodelverse.ai" ) 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" } }, "required": ["location"] } } ] message = client.messages.create( model="claude-sonnet-4-5-20250929", max_tokens=1024, tools=tools, messages=[ {"role": "user", "content": "What's the weather like in Beijing?"} ] ) print(message.content)

Model List

For more supported Claude-compatible models, please see [Get Model List] or visit the UModelverse Model Center.

For more details on the fields, see the official Anthropic documentation