How to properly authenticate with langsmith API run endpoint

I just set up my langsmith account and generated my personal API key. However when I try to make requests to the runs endpoint I keep getting unauthorized errors.

curl -X POST https://api.smith.langchain.com/runs \
     -H "Authorization: Bearer your_api_key_here" \
     -H "Content-Type: application/json" \
     -d '{"name":"Sample Run","run_type":"llm"}'

Am I missing some configuration steps or additional authentication requirements to access this endpoint successfully?

Beyond swapping the API key, try using the X-API-Key header instead of (or with) the Authorization header. Some endpoints need both for auth to work. I ran into this same issue - certain langsmith endpoints are super picky about headers. Also check your API key permissions in account settings. Not all keys get write access to the runs endpoint by default. Add -H "X-API-Key: your_actual_key" to your curl command and see if that fixes the unauthorized error.

Double-check your curl syntax - I had weird auth failures because of line breaks in the middle of headers. Put everything on one line or use proper backslash escaping. Also, some terminals mess up quotes around JSON data. Use single quotes around the whole -d parameter instead.

hey tom, you’re using a placeholder in your bearer token - replace your_api_key_here with your actual api key from langsmith settings. also check there’s no extra spaces when you copy/paste it

Check if you’re including your project ID in the request. Langsmith’s API needs a valid project context even for basic run creation. Grab your project ID from the langsmith dashboard under project settings. Add it as a query parameter like ?project_id=your_project_id to your endpoint URL. I had the same auth issues until I figured out the API was rejecting requests without proper project scope. Also make sure your account’s fully activated - new accounts sometimes can’t use API write operations until you verify your email.

Hit this same issue last month when adding langsmith to our monitoring setup. It’s usually the endpoint URL.

Use https://api.smith.langchain.com/api/v1/runs instead of just /runs. The versioned path matters for auth.

Check your API key starts with ls__ - if not, you grabbed the wrong token from your dashboard. The runs endpoint won’t accept other key formats.

If you’re still getting 401s, test with a GET to https://api.smith.langchain.com/api/v1/sessions first. That endpoint’s less picky and will show if your auth setup is busted.