Refreshing custom AI provider authentication headers?

First, I just upgraded to LinqPad 9 and want to say how impressed I am. The new UI is wonderful and a great improvement.

I've been playing with the AI features and have a question about custom AI providers. My company uses Claude Code via a custom Anthropic endpoint. I have been able to get this working in LinqPad by getting the authentication header values from my Claude settings.json file, but our authentication tokens are only valid for an hour (sigh). There's a plugin for VS Code that automatically refreshes this token and updates settings.json.

Is there any way to tell LinqPad to get the authentication data directly from my primary settings.json, or some programmatic hook that I can write to read the JSON and give LinqPad current auth headers?

Thanks!

Answers

  • Are you using LINQPad's embedded Claude Code (Settings -> Claude Code) or have you set it up Anthropic as a general AI Provider (in Settings -> AI)?

  • I've set up both. The embedded Claude Code terminal seems to be working fine, so it is finding the authentication token somehow (I thought LinqPad had it's own separate settings.json file, so not sure where it's coming from - it's not in my environment variables).

    The general AI provider works great for code completion as long as the token is valid, but as soon as it expires, LinqPad shows me an Unauthorized error coming from the gateway.

    I did try enabling the "Use Claude Code as the default provider for inline AI" but it doesn't seem to work for code completion or AI chat. When I try using those features without the general AI provider set up, LinqPad just sends me to the general AI settings page.

  • JoeAlbahari
    edited August 13

    Regarding Chat, you can use Claude Code for this - it's been prompted to work as a general chat agent as well as for LINQPad tasks. The "AI Chat" tab is preferable only if you want a completely clean session, with no tools and a clean system prompt, maybe for prompt engineering.

    But for completion, yes, you'll need to set up Anthropic as an AI provider.

    Your best bet might be to write a LINQPad script to update the API key.

    The key that Claude Code uses normally comes from ~/.claude/.credentials.json. Call Util.SetPassword(slotName, apiKey) to update the API key. To see the slotName, go to LINQPad's Password Manager (Tools menu). The default is ".ai:apikey.anthropic".

    Claude Code in LINQPad can write the script for you.

    Once it's working use Windows Task Scheduler to run it every 15 minutes or so via LPRun9. Note that the scheduled task must run in your own account so that DPAPI works. "Run only when user is logged on" is the safe setting. And enabling "Run task as soon as possible after a scheduled start is missed" covers the laptop-sleep case. Claude should be able to set this up for you as well.