Unable to connect to Anthropic Claude using CrewAI

Hello, I am using multiagent customer support example from deeplearning.ai course to some testing. In course it connects to openai but I am trying to use clause. Even after making necessary change I am still getting error openai key not found which I guess it is not supposed to expect. Please guide me how to proceed.

Here is a error I am getting -
— openai.AuthenticationError: Error code: 401 - {‘error’: {‘message’: ‘Incorrect API key provided: fake. You can find your API key at .’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘invalid_api_key’}}`

Following is my code `
import os
import warnings
warnings.filterwarnings(“ignore”)
import requests

from dotenv import load_dotenv
from crewai import Agent, Task, Crew , LLM
from crewai_tools import SerperDevTool,
ScrapeWebsiteTool,
WebsiteSearchTool

from langchain_anthropic import ChatAnthropic

Load environment variables from the .env file (if present)

load_dotenv()
ANTHROPIC_API_KEY = os.environ.get(‘ANTHROPIC_API_KEY’) or ‘you-will-never-guess’

llm = ChatAnthropic(
model=“claude-3-5-sonnet-20240620”,
base_url=“https://api.anthropic.com/v1/complete”,
api_key=os.environ.get(‘ANTHROPIC_API_KEY’)
)

support_agent = Agent(
role=“Senior Support Representative”,
goal="Be the most friendly and helpful "
“support representative in your team”,
backstory=(
"You work at crewAI and "
" are now working on providing "
“support to {customer}, a super important customer "
" for your company.”
“You need to make sure that you provide the best support!”
“Make sure to provide full complete answers, "
" and make no assumptions.”
),
allow_delegation=False,
verbose=True,
llm=llm
)

support_quality_assurance_agent = Agent(
role=“Support Quality Assurance Specialist”,
goal="Get recognition for providing the "
“best support quality assurance in your team”,
backstory=(
"You work at crewAI and "
"are now working with your team "
"on a request from {customer} ensuring that "
"the support representative is "
“providing the best support possible.\n”
"You need to make sure that the support representative "
“is providing full”
“complete answers, and make no assumptions.”
),
verbose=True,
llm=llm
)

docs_scrape_tool = ScrapeWebsiteTool(
website_url=“https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/
)

inquiry_resolution = Task(
description=(
“{customer} just reached out with a super important ask:\n”
“{inquiry}\n\n”
"{person} from {customer} is the one that reached out. "
"Make sure to use everything you know "
“to provide the best support possible.”
"You must strive to provide a complete "
“and accurate response to the customer’s inquiry.”
),
expected_output=(
"A detailed, informative response to the "
"customer’s inquiry that addresses "
“all aspects of their question.\n”
"The response should include references "
"to everything you used to find the answer, "
"including external data or solutions. "
"Ensure the answer is complete, "
"leaving no questions unanswered, and maintain a helpful and friendly "
“tone throughout.”
),
tools=[docs_scrape_tool],
agent=support_agent,
)

quality_assurance_review = Task(
description=(
"Review the response drafted by the Senior Support Representative for {customer}'s inquiry. "
"Ensure that the answer is comprehensive, accurate, and adheres to the "
“high-quality standards expected for customer support.\n”
"Verify that all parts of the customer’s inquiry "
"have been addressed "
“thoroughly, with a helpful and friendly tone.\n”
"Check for references and sources used to "
" find the information, "
"ensuring the response is well-supported and "
“leaves no questions unanswered.”
),
expected_output=(
"A final, detailed, and informative response "
“ready to be sent to the customer.\n”
"This response should fully address the "
"customer’s inquiry, incorporating all "
“relevant feedback and improvements.\n”
"Don’t be too formal, we are a chill and cool company "
“but maintain a professional and friendly tone throughout.”
),
agent=support_quality_assurance_agent,
)

crew = Crew(
agents=[support_agent, support_quality_assurance_agent],
tasks=[inquiry_resolution, quality_assurance_review],
verbose=True,
memory=True
)

inputs = {
“customer”: “DeepLearningAI”,
“person”: “Andrew Ng”,
“inquiry”: "I need help with setting up a Crew "
"and kicking it off, specifically "
"how can I add memory to my crew? "
“Can you provide guidance?”
}
result = crew.kickoff(inputs=inputs)

print(result)`

Please help.

llm = LLM(
model=“custom-model-name”,
api_key=“your-api-key”,
base_url=“https://api.your-provider.com/v1
)
agent = Agent(llm=llm, …)

Thanks for your reply. I tried with this too but it’s still hitting openai. I have been trying since last 2 days now but no luck :slight_smile: I am about to give up on crewai now.

Memory=true requires an embedding llm and since you didnt specify one it may default to an openai one. Also did you check to see if that tool youre using requires an embedding llm?

Thank you. Turning off memory fixed issue. So it was using OpenAI embeddings by default which I missed. I will change embedder to different model. Appreciate your help.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.