Operations (sample payloads)

Main operations
Copy

Create Completion
Copy

Expects a prompt and returns a completion

Sample Input

1
{
2
"model": "claude-2.1",
3
"prompt": "\n\nHuman: What are the main differences between Python and JavaScript?\n\nAssistant:",
4
"max_tokens_to_sample": 1024,
5
"stop_sequences": [
6
"\n\nHuman:"
7
],
8
"temperature": 0.7,
9
"metadata": {
10
"user_id": "user_123456789"
11
},
12
"stream": false
13
}

Sample Output

1
{
2
"type": "completion",
3
"id": "cmpl-1234567890abcdef",
4
"completion": "There are several key differences between Python and JavaScript:\n\n1. Language type:\n - Python is a general-purpose programming language\n - JavaScript was originally designed for web development, but can now be used for various purposes\n\n2. Execution environment:\n - Python runs on a Python interpreter\n - JavaScript primarily runs in web browsers, but can also run on servers using Node.js\n\n3. Syntax:\n - Python uses indentation to define code blocks\n - JavaScript uses curly braces {} to define code blocks\n\n4. Data types:\n - Python has more built-in data types like tuples and sets\n - JavaScript has fewer primitive data types\n\n5. Object-oriented programming:\n - Python uses class-based OOP\n - JavaScript uses prototype-based OOP\n\n6. Typing:\n - Python is strongly typed\n - JavaScript is weakly typed\n\n7. Concurrency:\n - Python has built-in support for multi-threading and multiprocessing\n - JavaScript is single-threaded but uses an event loop for asynchronous operations\n\n8. Standard library:\n - Python has a extensive standard library\n - JavaScript has a smaller standard library, but a vast ecosystem of third-party packages\n\n9. Use cases:\n - Python is widely used in data science, AI, scientific computing, and backend development\n - JavaScript dominates frontend web development and is growing in backend development\n\nThese differences make each language better suited for different tasks, though there is also significant overlap in their capabilities.",
5
"stop_reason": "stop_sequence",
6
"model": "claude-2.1"
7
}

Create Message (Beta)
Copy

Send a structured list of input messages, and the model will generate the next message in the conversation.

Sample Input

1
{
2
"model": "claude-2.1",
3
"messages": [
4
{
5
"role": "user",
6
"content": {
7
"string": "What are the main differences between Python and JavaScript?"
8
}
9
}
10
],
11
"max_tokens": 1024,
12
"temperature": 0.7,
13
"system": "You are a helpful programming language expert.",
14
"metadata": {
15
"user_id": "user_123456789"
16
}
17
}

Sample Output

1
{
2
"id": "msg_1a2b3c4d5e6f7g8h9i0j",
3
"type": "message",
4
"model": "claude-2.1",
5
"role": "assistant",
6
"content": [
7
{
8
"type": "text",
9
"text": "There are several key differences between Python and JavaScript:\n\n1. Language type:\n - Python is a general-purpose programming language.\n - JavaScript was originally designed for web development but has expanded to other areas.\n\n2. Execution environment:\n - Python runs on a Python interpreter, typically on a server or local machine.\n - JavaScript primarily runs in web browsers, but can also run on servers (Node.js).\n\n3. Syntax:\n - Python uses indentation to define code blocks.\n - JavaScript uses curly braces {} to define code blocks.\n\n4. Typing:\n - Python is strongly typed but dynamically typed.\n - JavaScript is weakly typed and dynamically typed.\n\n5. Object-Oriented Programming (OOP):\n - Python uses class-based OOP.\n - JavaScript uses prototype-based OOP.\n\n6. Concurrency:\n - Python has built-in support for multi-threading and multiprocessing.\n - JavaScript is single-threaded but uses an event loop for asynchronous operations.\n\n7. Standard library:\n - Python has a extensive standard library.\n - JavaScript has a smaller standard library but a vast ecosystem of third-party packages.\n\n8. Use cases:\n - Python is popular for data science, AI, backend development, and scripting.\n - JavaScript dominates frontend web development and is growing in backend and mobile development.\n\nBoth languages have their strengths and are widely used in different domains of software development."
10
}
11
],
12
"stop_reason": "end_turn",
13
"stop_sequence": null
14
}

Raw HTTP request (advanced)
Copy

Perform a raw HTTP request with some pre-configuration and processing by the connector, such as authentication.

Sample Input

1
{
2
"method": "POST",
3
"url": {
4
"fullUrl": "https://api.anthropic.com/v1/completions"
5
},
6
"headers": {
7
"Content-Type": "application/json",
8
"X-API-Key": "sk-ant-api03-example-key"
9
},
10
"body": {
11
"raw": {
12
"model": "claude-2",
13
"prompt": "Explain quantum computing in simple terms",
14
"max_tokens_to_sample": 150,
15
"temperature": 0.7
16
}
17
}
18
}

Sample Output

1
{
2
"status": 200,
3
"headers": {
4
"Content-Type": "application/json",
5
"X-Request-ID": "req_abc123def456"
6
},
7
"body": {
8
"completion": "Quantum computing is like a super-powerful calculator that uses the weird rules of quantum physics. Instead of regular bits (0s and 1s), it uses quantum bits or 'qubits' that can be in multiple states at once. This allows quantum computers to solve certain complex problems much faster than regular computers. It's still a new technology, but it could revolutionize fields like cryptography, drug discovery, and financial modeling.",
9
"stop_reason": "max_tokens",
10
"model": "claude-2"
11
}
12
}