Native Claude API Usage Guide
Claude Models Can Be Accessed via the Official Native Interface
- This method is specific to Claude models. For non-Claude models, please use the OpenAI API format.
API Request Examples
1. Using curl
for API Requests:
curl https://aihubmix.com/v1/messages \ # Replace the official endpoint with AiHubMix’s API endpoint
--header "x-api-key: $ANTHROPIC_API_KEY" \ # Replace this with the API key you generated on AiHubMix
--header "anthropic-version: 2023-06-01" \
--header "content-type: application/json" \
--data \
'{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello, world"}
]
}'
2. Using the Python Library:
import anthropic
# Initialize the Anthropics client
client = anthropic.Anthropic(
# Replace this with the API key you generated on AiHubMix
api_key="ANTHROPIC_API_KEY",
base_url="https://aihubmix.com"
)
# Construct your message
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude"}
]
)
# Print the response content
print(message.content)
Using Claude in Applications (Example: Lobe-Chat)
Here’s how you can configure Claude models in a third-party application like Lobe-Chat:
- Navigate to the settings page and select Claude as your model provider.
- Enter your API Key from AiHubMix.
- Set the API proxy endpoint to:
https://aihubmix.com
- (Recommended) Enable the "Client Request Mode" option.
- Add your chosen model to the model list.
- It’s recommended to copy the model name from AiHubMix's settings page and paste it in the application.