File size: 808 Bytes
0a22466
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import streamlit as st
from anthropic import Anthropic

st.title("Anthropic API Key Test")

try:
    # Get API key from environment
    api_key = os.getenv('ANTHROPIC_API_KEY')
    if not api_key:
        st.error("❌ No API key found in environment variables")
        st.stop()
    
    # Try to initialize client
    client = Anthropic(api_key=api_key)
    
    # Try a simple API call
    response = client.messages.create(
        model="claude-3-opus-20240229",
        max_tokens=10,
        messages=[{"role": "user", "content": "Say hello"}]
    )
    
    st.success("✅ API key works! Got response from Claude")
    st.write("Response:", response.content[0].text)
    
except Exception as e:
    st.error(f"❌ Error: {str(e)}")
    st.write("Please check your API key configuration")