# Connect Xcode to Tokens

> Add Tokens as an internet-hosted chat provider in Xcode's Intelligence settings. Enter the URL without /v1, add your key and pick models in the chat model picker.

Xcode 26 and later can chat with models from a provider you add yourself. Apple requires the provider to support the Chat Completions API, which Tokens does. You add Tokens under **Xcode > Settings > Intelligence** as an **Internet Hosted** chat provider, and Xcode then lists the models your key can call.

This guide was checked against Apple's page "Setting up coding intelligence" (Xcode documentation, 2026) and Apple Developer Forums threads on custom providers, October 2026. Apple's page does not name an Xcode version. It was checked against the documentation, not run end to end with a live key.

## What you need

- Xcode 26 or later on a Mac. Use 26.3 or later, because a forum thread reports that Xcode 26.2 forgot added providers when it quit, and that 26.3 fixed it.
- A Tokens key. [API keys](/docs/api-keys) covers spend caps and allow-lists.
- Apple Intelligence turned on in System Settings. Apple's page does not say this, but guides from other providers list it as a requirement for any model provider in Xcode.

## Add Tokens

1. Choose **Xcode > Settings** and select **Intelligence** in the sidebar.
2. Under **Chat**, click **Add a Chat Provider** (some guides call it **Add a Model Provider**).
3. Select **Internet Hosted**.
4. Fill in the dialog, then click **Add**:

| Field              | What to enter                                                                    |
| ------------------ | -------------------------------------------------------------------------------- |
| **URL**            | `https://tokens.bd`, the gateway root with no `/v1`                         |
| **API Key**        | Your Tokens key, `tok_live_your_key`                                             |
| **API Key Header** | Leave empty (see below)                                                          |
| **Description**    | A label for yourself, such as `Tokens`                                           |

### Why the URL has no /v1

Apple's page says Xcode expects the provider to support `{Model provider URL}/v1/models` and `{Model provider URL}/v1/chat/completions`. So the URL you enter is the root, and Xcode adds `/v1` and the endpoint itself. For Tokens that root is `https://tokens.bd`, which makes Xcode call `https://tokens.bd/v1/models` and `https://tokens.bd/v1/chat/completions`.

Do not enter `https://tokens.bd/v1`. It already ends in `/v1`, so Xcode would request a doubled `/v1/v1/models` path that Tokens answers with 404 `unsupported_endpoint`. The same applies to a URL ending in `/chat/completions`.

### The API key header

Apple's page does not describe the **API Key Header** field. Guides from Vercel and OpenRouter, both written for Xcode 26, say that leaving it empty makes Xcode send the standard `Authorization` header. Tokens reads `Authorization: Bearer <key>`. Tokens also accepts the key in an `x-api-key` header, so if you must name a header, `x-api-key` with the bare key works. Do not type the word `Bearer` into the key field unless you set the header to `Authorization`, as the OpenRouter guide does.

### Where the key is kept

Apple does not document how Xcode stores the key, so this guide does not claim it is in the macOS Keychain. Enter the key only in this dialog. Do not put it in a project file, a scheme, an `.xcconfig` or a script that gets committed. Create the key for Xcode alone, with its own monthly spend cap, so you can revoke it without touching anything else.

## Pick a model

After you add the provider, click its row in the Intelligence settings. Xcode fills the **Models** table from the provider's model list. Mark the models you plan to use as favorites so they sit at the top of the picker. Open the chat from a project window and choose the model in the picker on the message field.

Tokens model ids always have a slash, for example `deepseek/deepseek-v4.1-flash`. Xcode takes ids from the list instead of asking you to type them, and the Vercel guide shows slash ids working, but Apple does not document the id format. The list holds only the models the key can call: a key with an allow-list, or an account with no active plan and no wallet balance, shows a short or empty list. [Choosing a model](/docs/choosing-a-model) helps with the choice.

Apple's page has no setting for context window, output limit or tool calling. Xcode sends the model id and the conversation, and the model's limits are whatever Tokens and the upstream enforce. Prefer a model with a large context window for chats that include many files, and see the [catalog](/models) for limits.

## What uses the custom provider

| Part of Xcode                                              | Uses Tokens?                                                                     |
| ---------------------------------------------------------- | -------------------------------------------------------------------------------- |
| Chat with a provider you added under **Chat**              | Yes                                                                              |
| Agents in the **Agents** section (Claude Agent, Codex)    | No. Apple says you enable and sign in to each agent separately                    |
| ChatGPT in Xcode, Claude Sonnet and Opus (Apple's built-in options) | No. They use their own accounts                                          |
| Agents you add through the Agent Client Protocol          | Not documented by Apple for custom providers. Each agent has its own settings    |

Apple notes that the agent or model you set up in Intelligence settings may access your project files and other information when it handles a request. Requests sent through the Tokens provider include that project context, so use a key and a model you trust with your code.

For agentic coding that runs through your Tokens key, use a tool with its own endpoint setting, such as [Claude Code](/docs/claude-code) in a terminal beside Xcode, and let Xcode do the chat.

Managed Macs: an MDM profile can turn off the coding assistant by setting `CodingAssistantAllowExternalIntegrations` to `false`. If the Intelligence settings are missing or locked, ask your Mac administrator.

## Check that it works

Test the key and the two paths Xcode uses before you add the provider:

```bash
export TOKENS_API_KEY=tok_live_your_key
curl -s https://tokens.bd/v1/models -H "Authorization: Bearer $TOKENS_API_KEY"
curl -s https://tokens.bd/v1/chat/completions \
  -H "Authorization: Bearer $TOKENS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "deepseek/deepseek-v4.1-flash", "max_tokens": 16, "messages": [{"role": "user", "content": "Reply with OK"}]}'
```

The first call must return a list of models. Then add the provider, wait for the model table to fill, pick a model and send a prompt in the chat. The request appears in your dashboard usage analytics.

## Troubleshooting

**"Provider is not valid - Models could not be fetched with the provided account details."** Xcode could not get a model list from `https://tokens.bd/v1/models`. Check, in this order: the URL has no `/v1`, no trailing path and no typo; the key is complete; the `curl` call above returns a list. Apple's engineer says Xcode supports only `/v1` path prefixes, which Tokens has.

**401 `invalid_api_key` or `missing_api_key`.** The key is wrong, empty, or was rotated, which stops the old secret immediately. If you set a custom header, make sure it matches how the key is written (see above). Edit the provider or add it again.

**404 `unsupported_endpoint`.** The path is wrong, usually a doubled `/v1`. Remove `/v1` from the URL.

**404 `model_not_found`.** The model id is unknown or inactive. Pick a model from the list again; the catalog can change.

**The model table is empty.** The key can call no models. An empty list usually means no active plan and no wallet balance, or an allow-list that excludes everything. Subscribe or top up in [billing](/dashboard/billing).

**402 `insufficient_credits`, 403 `monthly_spend_cap_exceeded` or 429 `rate_limited`.** Top up, raise the key's cap, or wait for `Retry-After`.

**The provider is gone after restarting Xcode.** Apple's forum reports this for Xcode 26.2. Update to 26.3 or later.

All codes are in [Errors](/docs/errors), and the request format is in [Chat Completions](/docs/chat-completions).

Sources: Apple, [Setting up coding intelligence](https://developer.apple.com/documentation/xcode/setting-up-coding-intelligence); Apple Developer Forums threads [816031](https://developer.apple.com/forums/thread/816031) and [810665](https://developer.apple.com/forums/thread/810665); Vercel's [Xcode guide](https://vercel.com/docs/ai-gateway/ecosystem/framework-integrations/xcode) and OpenRouter's [Xcode guide](https://openrouter.ai/docs/community/xcode) for the field details Apple does not give. Checked October 2026.

---
Page: https://tokens.bd/docs/xcode
