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.
Word:
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 console.anthropic.com (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 console.anthropic.com/settings/keys (visit) to get Claude 3 API keys.
- Right here, click on on “Create Key” and provides it a reputation.
- Now, copy the API key and retailer it securely.
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
- 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") api_key="my_api_key", ) message = shopper.messages.create( mannequin="claude-3-opus-20240229", max_tokens=1000, temperature=0.0, system="Reply solely in Yoda-speak.", messages=[ {"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 exchangemy_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
.
- Now, put it aside as
claude3.py
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
claude3.py
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 thesystem
immediate within the code to alter its conduct.
cd Desktop python claude3.py
- 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.