1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const axios = require('axios');
const fs = require('fs');
const path = require('path');
// helper function to help you convert your local images into base64 format
async function toB64(imgPath) {
const data = fs.readFileSync(path.resolve(imgPath));
return Buffer.from(data).toString('base64');
}
const api_key = "YOUR API-KEY";
const url = "https://api.segmind.com/v1/claude-4-sonnet";
const data = {
"messages": [
{
"role": "user",
"content" : "tell me a joke on cats"
},
{
"role": "assistant",
"content" : "here is a joke about cats..."
},
{
"role": "user",
"content" : "now a joke on dogs"
},
]
};
(async function() {
try {
const response = await axios.post(url, data, { headers: { 'x-api-key': api_key } });
console.log(response.data);
} catch (error) {
console.error('Error:', error.response.data);
}
})();An array of objects containing the role and content
Could be "user", "assistant" or "system".
A string containing the user's query or the assistant's response.
To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.
Edited by Segmind Team on October 28, 2025.
Claude 4 is part of Anthropic’s advanced AI model family, which features two distinct models: Claude Opus 4 and Claude Sonnet 4. Both of these models offer major AI enhancements with handling complex programming tasks, high-end reasoning capabilities, and advanced problem-solving. By integrating deep language understanding with coding skills, Claude 4 works as a flexible and useful model for developers, researchers, and technical professionals with their diverse tasks.
Claude 4 offers major improvements in coding capabilities, handling complex tasks efficiently, and excelling in executing thousands of sequential steps with a high level of contextual accuracy.
Claude 4 excels at handling simple and complex programming tasks, including code generation, debugging, optimization, and architectural planning across multiple programming languages.
Yes, Claude 4 supports advanced tool integration, parallel tool execution, and improved memory for accessing and processing local files.
If you have complex tasks that need long-running programming with agent tasks that need sustained performance, go with Claude Opus 4. For tasks that need a balanced approach in power and efficiency for basic coding and reasoning, opt for Claude Sonnet 4.
It is helpful when you organize the prompts clearly and directly, include all relevant context, and use the integrated tool whenever needed. If the tasks are complex, break the inputs into smaller, manageable steps, and be precise about what you need.