__init__() got an unexpected keyword argument 'api_key'

#61
by S0nna-0 - opened

Hi,

I tried to run the example code in 'Inference API' page as below. (Python 3)


from huggingface_hub import InferenceClient

client = InferenceClient(api_key="(My API Key)")

messages = [
{
"role": "user",
"content": "What is the capital of France?"
}
]

completion = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct",
messages=messages,
max_tokens=500
)

print(completion.choices[0].message)


And I keep getting TypeError as below.


TypeError Traceback (most recent call last)
Input In [94], in <cell line: 3>()
1 from huggingface_hub import InferenceClient
----> 3 client = InferenceClient(api_key="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")
5 messages = [
6 {
7 "role": "user",
8 "content": "What is the capital of France?"
9 }
10 ]
12 completion = client.chat.completions.create(
13 model="meta-llama/Llama-3.3-70B-Instruct",
14 messages=messages,
15 max_tokens=500
16 )

TypeError: init() got an unexpected keyword argument 'api_key'

Can anyone suggest idea to fix this problem? I don't understand why I get this error.

Thanks.

Sign up or log in to comment