We provide libraries in Python and Typescript that make it easier to work with the Anthropic API. If you are using Amazon Bedrock, see this guide.

Python

Python library GitHub repo

Example:

from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT

anthropic = Anthropic()
completion = anthropic.completions.create(
    model="claude-2",
    max_tokens_to_sample=300,
    prompt=f"{HUMAN_PROMPT} How many toes do dogs have?{AI_PROMPT}",
)
print(completion.completion)

Typescript

Typescript library GitHub repo

Example:

import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
	apiKey: 'my api key', // defaults to process.env["ANTHROPIC_API_KEY"]
});

async function main() {
  const completion = await anthropic.completions.create({
    model: 'claude-2',
    max_tokens_to_sample: 300,
    prompt: `${Anthropic.HUMAN_PROMPT} How many toes do dogs have?${Anthropic.AI_PROMPT}`,
  });
  console.log(completion.completion);
}
main().catch(console.error);