Spaces:
Sleeping
Sleeping
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") |