跳转到主要内容

Xcode

import { Steps } from "~/components";

Xcode supports internet-hosted chat providers that use the OpenAI Chat Completions API. Point a chat provider at an AI Gateway custom domain protected by Cloudflare Access. Xcode authenticates with an Access service token stored as its API key.

This integration uses static credentials. Xcode cannot use cloudflared to generate short-lived Access tokens.

Prerequisites

Before you start, you need:

:::note Service token requests do not include cf.user_id because they do not represent an individual Access user. You cannot filter AI Gateway logs by user for these requests. :::

  1. In Xcode, go to Xcode > Settings > Intelligence.

  2. Under Chat, select Add a Chat Provider > Internet Hosted.

  3. Enter a name for the provider, such as AI Gateway.

  4. For URL, enter your AI Gateway custom domain followed by /compat.

    Replace ai.example.com with your custom domain.

    https://ai.example.com/compat
    

    Xcode appends /v1/models to list available models. It sends prompts to /v1/chat/completions. AI Gateway accepts both paths under the compat endpoint.

    :::note The /compat endpoint is deprecated for standard single-model calls. Xcode requires an endpoint that supports both /v1/models and /v1/chat/completions. The AI Gateway REST API does not provide a /v1/models endpoint. :::

  5. For API Key, enter the following single-header service token value. Replace <CLIENT_ID> and <CLIENT_SECRET> with your Access service token values.

    {"cf-access-client-id":"<CLIENT_ID>","cf-access-client-secret":"<CLIENT_SECRET>"}
    
  6. Set API Key Header to Authorization.

  7. Select Add.

  8. Enable a model, then select it in the coding assistant and send a prompt. Requests now route through AI Gateway.

For more information about custom chat providers, refer to Setting up coding intelligence.

To confirm traffic reaches AI Gateway, refer to Verify it works.