AI Tools

How to Access Claude 3 API for Opus and Sonnet Models (With Examples)

Anthropic launched a brand new household of Claude 3 fashions which embrace Opus (largest), Sonnet (mid-size), and Haiku (smallest). The corporate has additionally made the API for Claude 3 fashions accessible instantly.

Whereas Claude 3 API pricing, particularly for the Opus mannequin, is kind of costly compared to GPT-4 Turbo, customers and builders need to take a look at the mannequin’s capabilities. So right here is a straightforward tutorial on entry Claude 3 API for Opus and Sonnet fashions. We now have additionally added a couple of code examples so that you can begin testing the fashions.

Anthropic is presently providing Claude 3 API value $5 in free credit. Before you purchase the API, you’ll be able to declare free credit and check Opus and Sonnet fashions immediately.

Entry Claude 3 API Key For Free

  • Head to (visit) and create an account.
  • Subsequent, you will notice a banner on prime informing customers about Claude providing $5 in free credit. Click on on “Declare“.
  • Enter your cell quantity and confirm it. You’re virtually accomplished.
  • Now, click on on “Get API Keys” on the dashboard. It’s also possible to head to (visit) to get Claude 3 API keys.
get claude 3 API key
  • Right here, click on on “Create Key” and provides it a reputation.
name your API key
  • Now, copy the API key and retailer it securely.
copy the API key

Tutorial to Use Claude 3 API With Examples

  • Go forward and arrange Python together with Pip in your laptop.
  • After that, open Terminal and run the beneath command to put in the Claude library.
pip set up anthropic
install claude library via pip
  • Anthropic has added some nice examples in its documentation for Claude 3 API testing. You’ll be able to copy the beneath code and paste it right into a code editor like Notepad++.
import anthropic

shopper = anthropic.Anthropic(
    # defaults to os.environ.get("ANTHROPIC_API_KEY")

message = shopper.messages.create(
    system="Reply solely in Yoda-speak.",
        {"role": "user", "content": "How are you today?"}

print(message.content material)
  • The code is already utilizing the most important Claude 3 Opus mannequin (claude-3-opus-20240229). You simply must exchange my_api_key with the precise API key you copied above. If you wish to use the Sonnet mannequin, use this mannequin title: claude-3-sonnet-20240229.
code to demonstrate claude 3 opus API
  • Now, put it aside as in your Desktop or your most well-liked location. It’s also possible to title it otherwise, however make certain .py is appended.
  • Lastly, fireplace up Terminal, and transfer to the Desktop. Subsequent, run the file. It should reply the query set within the code. Right here, it replies like Yoda to the query, “How are you at present?” It’s also possible to change the system immediate within the code to alter its conduct.
cd Desktop
run code using claude 3 api
  • Aside from that, you’ll be able to check out Simon Willison’s newly launched plugin for Claude 3 fashions with ease.

So that’s how one can shortly entry the Claude 3 API and check each Opus and Sonnet fashions. Anthropic is presently not providing API for the smallest Haiku mannequin. If that adjustments sooner or later, we are going to let . Anyway, that’s all from us. If you’re trying to entry the Gemini API key, observe our linked information. And you probably have any questions, tell us within the remark part beneath.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button