Endpoint reference / Provider credentials

Provider credentials.

Workspace owners and admins store the Credentials Sensei runs each provider on. A workspace can hold several auth methods per provider, and one of them is active at a time. To store a key or change the active method, send PUT /api/organizations/{workspaceId}/ai-provider with an operation. Any member can read the Credentials, with every secret masked.

MethodPathDescription
GET/api/organizations/{workspaceId}/ai-providerRead the workspace credentials and active auth method per provider, with every login of claude_code, codex and muse_code oldest first, and every saved key of each API-key method (anthropic and openai api_key, zai coding_plan, moonshot kimi_code, deepseek deepseek_api, ollama ollama_cloud, opencode opencode_go) as apiKeys, oldest first, with its name and which one is in use. Secrets are masked.
PUT/api/organizations/{workspaceId}/ai-providerStore or switch workspace credentials. The body is one of the operation variants; a key is tested before it is kept. On an API-key method a key replaces the key in use (or adds the first), and no key re-selects the method on its key in use; POST /api/organizations/{workspaceId}/ai-provider/keys adds another key. Admins only.
DELETE/api/organizations/{workspaceId}/ai-provider?provider=&authMethod=&loginId=Remove the credentials of one auth method, every saved key of it included, or with loginId one login of claude_code, codex or muse_code. Which methods a provider takes is not in the schema. Admins only.
GET/api/organizations/{workspaceId}/ai-provider/claude-usage?fresh=&loginId=Read the session and weekly utilization of the workspace's Claude login: the one in use, or the one loginId names. 400 when the workspace holds no such Claude login or it needs reconnecting.
GET/api/organizations/{workspaceId}/ai-provider/codex-usage?fresh=&loginId=Read the session and weekly utilization of the workspace's Codex login: the one in use, or the one loginId names. 400 when the workspace holds no such Codex login or it needs reconnecting.
GET/api/organizations/{workspaceId}/ai-provider/coding-plan-usage?fresh=&keyId=Read the session and weekly utilization of one of the workspace's GLM Coding Plan keys: the one keyId names, else the key in use. The reading is stored on the key: a key whose reading names a window rotates under Subscriptions with the workspace's other such keys, and one GLM says has none leaves it. 400 when the workspace holds no Coding Plan key, or none keyId names.
GET/api/organizations/{workspaceId}/ai-provider/deepseek-usage?fresh=Read the balance of the workspace's DeepSeek API key, one amount per currency, in place of usage windows. 400 when the workspace holds no DeepSeek API key.
GET/api/organizations/{workspaceId}/ai-provider/googleRead saved workspace Gemini methods and selection. Secrets are masked.
PUT/api/organizations/{workspaceId}/ai-provider/googleValidate and save a workspace Gemini API key, with an optional name. With neither credentialId nor add it replaces the key in use (the selected Gemini API key, else the oldest; with none saved it adds the first, unselected), as this call always has; with credentialId it replaces that key; with add: true it adds another without selecting it (up to 20; 409 API_KEY_LIMIT past that). 409 API_KEY_DUPLICATE for a key already saved. With credentialId and name but no apiKey it only renames that key. 404 for a credentialId this workspace does not hold. add and credentialId together are refused. Admins only.
DELETE/api/organizations/{workspaceId}/ai-provider/googleRemove both workspace Gemini methods and clear selection. Admins only.
PUT/api/organizations/{workspaceId}/ai-provider/google/methodSelect a saved workspace Gemini method with its selection revision; for gemini_api, credentialId picks which saved key (404 for a key this workspace does not hold). Admins only.
DELETE/api/organizations/{workspaceId}/ai-provider/google/methodRemove one workspace Gemini method, or with credentialId one Antigravity sign-in or one Gemini API key. Removing the selected method leaves none selected; removing the selected sign-in moves to another one, and removing the selected Gemini API key moves to the oldest key left. A method's last one removes the method. 404 for a credentialId this workspace does not hold under that method. Admins only.
GET/api/organizations/{workspaceId}/ai-provider/google/usage?fresh=&loginId=Read the session and weekly utilization of the workspace's Antigravity sign-in, whichever Gemini method is selected: its stored reading, from its latest turn or a live read, while that is under 5 minutes old, and otherwise a live read from Google with the sign-in's own token, stored on the sign-in. When the live read fails it is the stored reading, and null before there is one. A read never changes the selected method or a limit. 400 when the workspace holds no such sign-in or it needs reconnecting.
GET/api/organizations/{workspaceId}/ai-provider/grok-usage?fresh=&loginId=Read a workspace SuperGrok login's weekly usage: its stored reading while under five minutes old, otherwise a live read with its saved access token. A failed live read returns the stored reading, or null before one exists. A free reading begun at least fifteen minutes after a limit may lift that unchanged mark. An xAI API key has no reading. 400 when the named login is absent or needs reconnecting.
POST/api/organizations/{workspaceId}/ai-provider/help-requestAsk the workspace owners and admins to fix a provider. Repeated requests within one hour notify them once.
POST/api/organizations/{workspaceId}/ai-provider/keysSave one more API key of a workspace method (anthropic or openai api_key, zai coding_plan, moonshot kimi_code, deepseek deepseek_api, ollama ollama_cloud, opencode opencode_go), with an optional name, after one validation call to the provider. A GLM Coding Plan, Kimi Code, Ollama Cloud or OpenCode Go key's plan is read once too, without failing the save: a key whose reading names a window rotates under Subscriptions with the workspace's other such keys, one with none is unverified and runs only when picked. The method's first key is the key in use and makes the method active; a later key waits until it is picked or, under Subscriptions, rotates. Up to 20 keys per method: 409 API_KEY_LIMIT past that, 409 API_KEY_DUPLICATE for a key already saved. Answers the workspace credentials. Admins only.
PATCH/api/organizations/{workspaceId}/ai-provider/keysSwitch the workspace's GLM Coding Plan (zai), Kimi Code (moonshot), Ollama Cloud (ollama) or OpenCode Go (opencode) keys to Subscriptions: from the next Turn every key whose plan reading names a window rotates, lowest usage first, a key at its limit sitting out until its reset, and a key with no reading never runs. The key marked in use becomes one of them and its method the provider's active one. Picking a key with no reading (PATCH keys/{keyId} with use: true) leaves Subscriptions for that key alone. 404 when no key of the provider has a plan reading. Ollama rotates in Chat Sessions only. Answers the workspace credentials. Admins only.
PATCH/api/organizations/{workspaceId}/ai-provider/keys/{keyId}Change one saved workspace API key, by its id under apiKeys: apiKey replaces its secret after one validation call (the key in use stays in use) and, for GLM Coding Plan, Kimi Code and Ollama Cloud, one read of its plan, which never fails the save; name renames it (null or empty clears it); use: true makes it the key in use and its method the provider's active one. Picking a GLM, Kimi or Ollama key with no plan reading runs work on that key alone; picking one with a reading keeps Subscriptions, where every key with a reading rotates. Any of them together. 404 for a key this workspace does not hold. Answers the workspace credentials. Admins only.
DELETE/api/organizations/{workspaceId}/ai-provider/keys/{keyId}Remove one saved workspace API key, by its id under apiKeys. Removing the key in use makes the oldest key left the key in use, or under Subscriptions the oldest key left with a plan reading; removing a method's last key removes the method. 404 for a key this workspace does not hold. Answers the workspace credentials, which name the key now in use. Admins only.
GET/api/organizations/{workspaceId}/ai-provider/kimi-code-usage?fresh=&keyId=Read the session and monthly utilization of one of the workspace's Kimi Code keys: the one keyId names, else the key in use. The reading is stored on the key: a key whose reading names a window rotates under Subscriptions with the workspace's other such keys, and one Kimi says has none leaves it. 400 when the workspace holds no Kimi Code key, or none keyId names.
POST/api/organizations/{workspaceId}/ai-provider/login/antigravityStart a workspace Antigravity sign-in: another account, or with credentialId a reconnect of that one. Up to 20 accounts. Returns authorizationUrl at once: open it, then paste the code the Antigravity page shows into complete. Admins only.
POST/api/organizations/{workspaceId}/ai-provider/login/antigravity/cancelCancel workspace Antigravity sign-in. Admins only.
POST/api/organizations/{workspaceId}/ai-provider/login/antigravity/completeComplete workspace Antigravity sign-in with the code the Antigravity page shows (or that page's whole URL); without a code it only reads the sign-in. A refused code answers 400 and leaves the sign-in open for another; an account already connected answers 409 PROVIDER_LOGIN_DUPLICATE. Admins only.
POST/api/organizations/{workspaceId}/ai-provider/logins/recheckRe-check usage for the workspace's logins of one provider (including SuperGrok on xai) at their limit, without waiting for their reset: every login of the provider, or the one loginId names; for zai, moonshot, ollama and opencode the workspace's GLM Coding Plan, Kimi Code, Ollama Cloud or OpenCode Go keys work runs on, by their id under apiKeys, read live with their reading stored. On google, every Antigravity sign-in not awaiting a reconnect is read live and its reading stored, which lifts a block left by an older reading. Admins only. Returns cleared, stillAtLimit and unreadable counts and retryAt, the earliest remaining reset, or null.
GET/api/organizations/{workspaceId}/ai-provider/muse-usage?fresh=&loginId=Read the session and weekly utilization of the workspace's Muse Code login: the one in use, or the one loginId names. It is the stored reading, from the login's latest turn, its sign-in, its last usage limit or a live read, while that is under 5 minutes old, and otherwise a live read from Meta; when the live read fails it is the stored reading, and null before there is one. A usage-limit reading holds only the window that hit the limit, at 100%. 400 when the workspace holds no such Muse Code login or it needs reconnecting.
GET/api/organizations/{workspaceId}/ai-provider/ollama-usage?fresh=&keyId=Read the included usage of one of the workspace's Ollama Cloud keys, from Ollama's balance: the one keyId names, else the key in use. A credit plan reports its included credits for the billing period as credits (percent used, and the period's end), an older plan its session and weekly windows; purchased credits are never counted. The reading is stored on the key: a key whose reading names a window rotates under Subscriptions in Chat Sessions with the workspace's other such keys, and one with none leaves it. Ollama allows 10 balance reads a minute per user, so readings are cached 5 minutes unless fresh=true. 400 when the workspace holds no Ollama Cloud key, or none keyId names.
GET/api/organizations/{workspaceId}/ai-provider/ollama/models?method=&q=&cursor=List the models of the workspace's Ollama Cloud key, 25 a page: the ones the model picker shows first, then the rest, each by name. q searches every model. 502 with the reason when Ollama does not answer, which marks the key unreachable.
PUT/api/organizations/{workspaceId}/ai-provider/ollama/modelsShow one Ollama model in the workspace's model picker, or stop showing it. Admins only.
GET/api/organizations/{workspaceId}/ai-provider/opencode-usage?fresh=&keyId=Read the rolling, weekly and monthly utilization of one of the workspace's OpenCode Go keys: the one keyId names, else the key in use. The reading is stored on the key: a key whose reading names a window rotates under Subscriptions with the workspace's other such keys, and one OpenCode says has none leaves it. 400 when the workspace holds no OpenCode Go key, or none keyId names.
GET/api/organizations/{workspaceId}/ai-provider/opencode/models?method=&q=&cursor=List the paid chat models of the workspace's OpenCode Go key, 25 a page: the ones the model picker shows first, then the rest, each by name. q searches every model.
PUT/api/organizations/{workspaceId}/ai-provider/opencode/modelsShow one OpenCode Go model in the workspace's model picker, or stop showing it. Admins only.
GET/api/organizations/{workspaceId}/ai-provider/token-usageRead the tokens Sensei spent on the workspace's Credentials, per Provider and per login or key method, over the last 7 days, the last 30 days and everything recorded: input (uncached), cache read, cache write and output, kept apart. Each total gives its recorded items, how many reported no counts (missing, never added as 0), how many made no model call and how many are still in progress. Covers only work run through Sensei since recording began, from firstStartedAt; members' own Subscriptions and Sensei are never included. Owners and admins only.
POST/api/organizations/{workspaceId}/provider-login/claudeStart a Claude login for the workspace: open the returned url in a browser, then pass the code it shows and loginToken to complete within 15 minutes. Admins only.
POST/api/organizations/{workspaceId}/provider-login/claude/completeFinish a Claude login with the loginToken from start and the code from the browser (code, code#state, or the whole callback URL). A refused code answers 200 with authenticated false. Admins only.
POST/api/organizations/{workspaceId}/provider-login/codexStart a Codex login for the workspace: enter userCode at verificationUrl in a browser, then call complete with loginToken until it answers authenticated. Admins only.
POST/api/organizations/{workspaceId}/provider-login/codex/completePoll a Codex login with the loginToken from start: authenticated false until the code is approved in the browser, so repeat every intervalSeconds; restart true means start again. Admins only.
POST/api/organizations/{workspaceId}/provider-login/museStart a Muse Code login for the workspace: open verificationUrl in a browser and approve userCode, then call complete with loginToken until it answers authenticated. Admins only.
POST/api/organizations/{workspaceId}/provider-login/muse/completePoll a Muse Code login with the loginToken from start: authenticated false until the code is approved in the browser, so repeat every intervalSeconds; restart true means start again. The first login makes muse_code the active method. Admins only.

In the web app this is Settings > your workspace > AI Providers. To connect your own Claude, Codex, GLM Coding Plan, Kimi Code or DeepSeek API access instead, see Account. Which of the two runs a given session is explained on AI providers.

Read the workspace's Credentials

Read each provider's stored auth methods and which one is active.

curl -s https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/ai-provider \
  -H "Authorization: Bearer $KOSUKE_API_KEY"
{
  "data": {
    "defaultModel": null,
    "providers": {
      "anthropic": {
        "activeAuthMethod": "claude_code",
        "selectable": true,
        "authMethods": {
          "api_key": { "configured": true, "maskedApiKey": "sk-ant-...9f2c", "authenticatedAt": "2026-08-11T14:02:31.000Z" },
          "aws_bedrock": { "configured": false },
          "claude_code": {
            "configured": true,
            "email": "ops@acme.dev",
            "authenticatedAt": "2026-09-20T07:45:12.000Z",
            "logins": [
              { "id": "3d7a1f52-9c4e-4b08-a6e1-5f2b8c9d0e47", "label": "ops@acme.dev", "status": "available", "needsReauth": false, "exhaustedUntil": null, "authenticatedAt": "2026-09-20T07:45:12.000Z" }
            ]
          }
        }
      },
      "openai": {
        "activeAuthMethod": "api_key",
        "selectable": true,
        "authMethods": {
          "api_key": { "configured": true, "maskedApiKey": "sk-proj...41ab", "authenticatedAt": "2026-08-11T14:05:03.000Z" },
          "codex": { "configured": false, "logins": [] }
        }
      },
      "zai": {
        "activeAuthMethod": null,
        "selectable": false,
        "authMethods": { "coding_plan": { "configured": false } }
      },
      "moonshot": {
        "activeAuthMethod": null,
        "selectable": false,
        "authMethods": { "kimi_code": { "configured": false } }
      },
      "deepseek": {
        "activeAuthMethod": null,
        "selectable": false,
        "authMethods": { "deepseek_api": { "configured": false } }
      }
    }
  }
}
FieldMeaning
activeAuthMethodThe method this provider runs on, or null when none is active.
selectabletrue when the active method works. A login that needs reconnecting makes it false.
authMethods.<method>.configuredSensei holds this method's key or login.
maskedApiKeyThe first 7 and last 4 characters of a stored key.
emailThe account behind a Claude Code or Codex login.
needsReauthPresent and true when a Claude Code or Codex login needs reconnecting.
regionThe AWS region of a Bedrock key.
loginsEvery Claude Code or Codex login of the method, oldest first. The oldest login wins a tie when usage is close. Each has id, label, status, needsReauth, exhaustedUntil and authenticatedAt. label is the account email.
logins[].statusavailable, limit_reached or reconnect_required. exhaustedUntil is set only on limit_reached.

defaultModel is the Workspace Default Model when its provider can run, otherwise the model Sensei would choose from the first usable provider, and null only when no provider can run. savedDefaultModel is the Workspace Default Model as saved, and hasSavedDefaultModel says whether one is saved. A member's own Default Model is on Account.

In the CLI, run kosuke providers get <workspaceId>.

Store a key or switch the active method

Set operation to one of these values. Owners and admins only. default_model with a model field sets the Workspace Default Model and answers 400 BAD_REQUEST when that model’s provider cannot run.

operationAuth methodOther fields
anthropic_api_keyAnthropic API keyanthropicApiKey. Leave it out to switch back to the key already stored.
anthropic_aws_bedrockAnthropic on AWS Bedrockregion, required. bedrockApiKey, which you leave out to reuse the stored key. validationModel, an optional model value to test the key against.
anthropic_claude_codeClaude Code loginNone. Makes a stored login active. Connect the login first, as below.
openai_api_keyOpenAI API keyopenaiApiKey. Leave it out to switch back to the key already stored.
openai_codexCodex loginNone. Makes a stored login active. Connect the login first, as below.
zai_coding_planGLM Coding PlancodingPlanKey. Leave it out to switch back to the key already stored.
moonshot_kimi_codeKimi CodekimiCodeKey. Leave it out to switch back to the key already stored.
deepseek_deepseek_apiDeepSeek APIdeepseekApiKey, a key from the DeepSeek Platform. Leave it out to switch back to the key already stored.

Sensei tests a new key with one call to the provider before it keeps it. A refused key answers 400 BAD_REQUEST with the provider's reason. A DeepSeek API key with an empty balance passes the test and is stored. A key that passes is stored and becomes the active method at once. validationModel only picks the model for that test and defaults to anthropic:opus__xhigh.

curl -s -X PUT https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/ai-provider \
  -H "Authorization: Bearer $KOSUKE_API_KEY" \
  --json '{ "operation": "openai_api_key", "openaiApiKey": "'"$OPENAI_API_KEY"'" }'

The response has the same body as the read above. Existing sandboxes that run that provider on the workspace's Credentials receive the change. A sandbox running on a member's Subscription keeps that Subscription.

In the CLI, run kosuke providers set <workspaceId> --body '{"operation":"anthropic_claude_code"}'.

Connect a Claude Code login

A Claude Code login takes two calls and one visit to Claude in a browser. Owners and admins only.

  1. Start the login.

    curl -s -X POST https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/provider-login/claude \
      -H "Authorization: Bearer $KOSUKE_API_KEY"
    
    { "data": { "url": "https://claude.com/cai/oauth/authorize?code=true&client_id=...", "loginToken": "a3f9c2...e81d" } }
    
  2. Open url in a browser, sign in to Claude and authorize. The page shows a code.

  3. Within 15 minutes, send the code with the loginToken. code takes the code, the code with its #state suffix, or the whole callback URL.

    curl -s https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/provider-login/claude/complete \
      -H "Authorization: Bearer $KOSUKE_API_KEY" \
      --json '{ "loginToken": "'"$LOGIN_TOKEN"'", "code": "'"$CODE"'" }'
    
    { "data": { "authenticated": true, "email": "ops@acme.dev" } }
    
  4. Read the answer. A refused code still answers 200. With authenticated: false, message says why. When restart is also true, go back to step 1. Otherwise paste the code again.

  5. Make the login the active method with PUT /api/organizations/{workspaceId}/ai-provider and { "operation": "anthropic_claude_code" }. A finished login is stored, and it stays inactive until you do.

In the CLI, run kosuke providers logins start <workspaceId> --provider claude_code, then kosuke providers logins complete <workspaceId> --login-token <token> --code <code> --provider claude_code.

Connect a Codex login

A Codex login uses a device code that you enter on OpenAI's site. Owners and admins only.

  1. Start the login.

    curl -s -X POST https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/provider-login/codex \
      -H "Authorization: Bearer $KOSUKE_API_KEY"
    
    {
      "data": {
        "userCode": "WXYZ-1234",
        "verificationUrl": "https://auth.openai.com/codex/device",
        "intervalSeconds": 5,
        "loginToken": "a3f9c2...e81d"
      }
    }
    
  2. Open verificationUrl in a browser, sign in with the ChatGPT account and enter userCode.

  3. Poll every intervalSeconds with the loginToken.

    curl -s https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/provider-login/codex/complete \
      -H "Authorization: Bearer $KOSUKE_API_KEY" \
      --json '{ "loginToken": "'"$LOGIN_TOKEN"'" }'
    
  4. Read the answer. { "authenticated": false } means the code is not approved yet, so poll again. authenticated: true comes with the account email. restart: true means the code expired or OpenAI refused it, so go back to step 1.

  5. Make the login the active method with PUT /api/organizations/{workspaceId}/ai-provider and { "operation": "openai_codex" }.

In the CLI, run kosuke providers logins start <workspaceId> --provider codex, then kosuke providers logins complete <workspaceId> --login-token <token> --provider codex.

Remove Credentials

Delete the stored key or login of one auth method. Owners and admins only. The route answers 204.

providerauthMethod values
anthropicapi_key, aws_bedrock, claude_code
openaiapi_key, codex
zaicoding_plan
moonshotkimi_code
deepseekdeepseek_api
curl -s -X DELETE "https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/ai-provider?provider=openai&authMethod=api_key" \
  -H "Authorization: Bearer $KOSUKE_API_KEY"

Removing the active method leaves the provider with no active method. Its activeAuthMethod reads null until you switch to another one.

In the CLI, run kosuke providers delete <workspaceId> --provider openai --auth-method api_key.

Check usage

Read how much of its limits a Claude Code login, a Codex login, a GLM Coding Plan or a Kimi Code key has used, or the balance of a DeepSeek API key. Any member can read it, whether or not the method is active.

curl -s https://app.kosuke.ai/api/organizations/$WORKSPACE_ID/ai-provider/claude-usage \
  -H "Authorization: Bearer $KOSUKE_API_KEY"
{
  "data": {
    "session": { "utilization": 42, "resetsAt": "2026-09-30T14:00:00.000Z" },
    "week": { "utilization": 18, "resetsAt": "2026-10-04T09:00:00.000Z" },
    "fetchedAt": "2026-09-30T11:37:05.000Z"
  }
}

session is the 5-hour window and week the 7-day window. utilization is a percentage from 0 to 100. Either window is null when the provider reports none. Kimi Code has no weekly window, so its week is always null and its monthly window is in month. Sensei keeps an answer for up to 5 minutes, so fetchedAt says how fresh it is.

RouteReads
GET /api/organizations/{workspaceId}/ai-provider/claude-usageThe Claude Code login.
GET /api/organizations/{workspaceId}/ai-provider/codex-usageThe Codex login.
GET /api/organizations/{workspaceId}/ai-provider/coding-plan-usageThe GLM Coding Plan.
GET /api/organizations/{workspaceId}/ai-provider/kimi-code-usageThe Kimi Code key.
GET /api/organizations/{workspaceId}/ai-provider/deepseek-usageThe DeepSeek API key's balance.

A DeepSeek API key is paid as you go and has no windows. Its session and week are null, and balance carries the key's balance instead.

{
  "data": {
    "session": null,
    "week": null,
    "balance": { "available": true, "amounts": [{ "currency": "USD", "total": "12.40" }] },
    "fetchedAt": "2026-09-30T11:37:05.000Z"
  }
}

balance.available is false when the balance is too low to run a turn. balance.amounts holds one entry per currency the account holds, USD or CNY, with total as a decimal string. Sensei does not add the currencies together.

In the CLI, run kosuke providers usage get <workspaceId> --provider claude_code, and codex, coding-plan, kimi-code or deepseek in place of claude.

Errors

StatusCodeWhen
400BAD_REQUESTThe provider refused the key. You left out a key and none is stored. You picked a login method before connecting the login. The validationModel has no Bedrock equivalent, or the default_model provider cannot run. The provider and authMethod pair is invalid. A usage route found no login, GLM Coding Plan, Kimi Code or DeepSeek API key, or a login that needs reconnecting.
400VALIDATION_ERRORThe body fails the schema, such as an unknown operation or an empty code.
403FORBIDDENYou are not a member of the workspace, or you are a member calling a route for owners and admins.
503SERVICE_UNAVAILABLEOpenAI could not start a Codex login, or the provider did not return usage. Try again.

The full list is in Responses and errors.

Next steps