Skip to content
Docs

AI Gateway OIDC Authentication

The Vercel OIDC token is a way to authenticate your requests to the AI Gateway without needing to manage an API key. Vercel automatically generates the OIDC token that it associates with your Vercel project.

Vercel OIDC tokens are only valid for 12 hours, so you will need to refresh them periodically during local development. You can do this by running vercel env pull again.

  1. Before you can use the OIDC token during local development, ensure that you link your application to a Vercel project:

    terminal
    vercel link
  2. Pull the environment variables from Vercel to get the OIDC token:

    terminal
    vercel env pull
  3. With OIDC authentication, you can directly use the gateway provider without needing to obtain an API key or set it in an environment variable:

    The AI SDK resolves OIDC automatically when AI_GATEWAY_API_KEY isn't set. For the Python beta, install the Vercel integration with uv add "ai[vercel]". The HTTP client examples below read VERCEL_OIDC_TOKEN from the environment. For long-running Node.js processes on Vercel, use getVercelOidcToken() from @vercel/oidc at request time to obtain the current token.

    See the AI SDK OIDC reference for SDK configuration and usage.

    oidc.ts
    import { generateText } from 'ai';
     
    const { text } = await generateText({
      model: "anthropic/claude-sonnet-5",
      prompt: "Why is the sky blue?",
    });
     
    console.log(text);
    oidc_ai.py
    import asyncio
    import ai
     
    async def main():
        model = ai.get_model("anthropic/claude-sonnet-5")
        messages = [ai.user_message("Why is the sky blue?")]
        async with ai.stream(model, messages) as stream:
            async for event in stream:
                if isinstance(event, ai.events.TextDelta):
                    print(event.chunk, end="", flush=True)
        print()
     
    asyncio.run(main())
    oidc-chat.ts
    import OpenAI from 'openai';
     
    const client = new OpenAI({
      apiKey: process.env.VERCEL_OIDC_TOKEN,
      baseURL: 'https://ai-gateway.vercel.sh/v1',
    });
     
    const response = await client.chat.completions.create({
      model: "anthropic/claude-sonnet-5",
      messages: [{ "role": "user", "content": "Why is the sky blue?" }],
    });
     
    console.log(response.choices[0]?.message.content);
    oidc_chat.py
    import os
    from openai import OpenAI
     
    client = OpenAI(
        api_key=os.environ["VERCEL_OIDC_TOKEN"],
        base_url="https://ai-gateway.vercel.sh/v1",
    )
     
    response = client.chat.completions.create(
        model="anthropic/claude-sonnet-5",
        messages=[{"role": "user", "content": "Why is the sky blue?"}],
    )
     
    print(response.choices[0].message.content)
    oidc-chat.sh
    curl --fail-with-body https://ai-gateway.vercel.sh/v1/chat/completions \
      -H "Authorization: Bearer $VERCEL_OIDC_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
      "model": "anthropic/claude-sonnet-5",
      "messages": [
        {
          "role": "user",
          "content": "Why is the sky blue?"
        }
      ]
    }'
    oidc-messages.ts
    import Anthropic from '@anthropic-ai/sdk';
     
    const client = new Anthropic({
      apiKey: process.env.VERCEL_OIDC_TOKEN,
      baseURL: 'https://ai-gateway.vercel.sh',
    });
     
    const response = await client.messages.create({
      model: "anthropic/claude-sonnet-5",
      messages: [{ "role": "user", "content": "Why is the sky blue?" }],
      max_tokens: 1024,
    });
     
    for (const block of response.content) {
      if (block.type === 'text') console.log(block.text);
    }
    oidc_messages.py
    import os
    from anthropic import Anthropic
     
    client = Anthropic(
        api_key=os.environ["VERCEL_OIDC_TOKEN"],
        base_url="https://ai-gateway.vercel.sh",
    )
     
    response = client.messages.create(
        model="anthropic/claude-sonnet-5",
        messages=[{"role": "user", "content": "Why is the sky blue?"}],
        max_tokens=1024,
    )
     
    for block in response.content:
        if block.type == "text":
            print(block.text)
    oidc-messages.sh
    curl --fail-with-body https://ai-gateway.vercel.sh/v1/messages \
      -H "Authorization: Bearer $VERCEL_OIDC_TOKEN" \
      -H "Content-Type: application/json" \
      -H "anthropic-version: 2023-06-01" \
      -d '{
      "model": "anthropic/claude-sonnet-5",
      "messages": [
        {
          "role": "user",
          "content": "Why is the sky blue?"
        }
      ],
      "max_tokens": 1024
    }'
    oidc-responses.ts
    import OpenAI from 'openai';
     
    const client = new OpenAI({
      apiKey: process.env.VERCEL_OIDC_TOKEN,
      baseURL: 'https://ai-gateway.vercel.sh/v1',
    });
     
    const response = await client.responses.create({
      model: "anthropic/claude-sonnet-5",
      input: "Why is the sky blue?",
    });
     
    console.log(response.output_text);
    oidc_responses.py
    import os
    from openai import OpenAI
     
    client = OpenAI(
        api_key=os.environ["VERCEL_OIDC_TOKEN"],
        base_url="https://ai-gateway.vercel.sh/v1",
    )
     
    response = client.responses.create(
        model="anthropic/claude-sonnet-5",
        input="Why is the sky blue?",
    )
     
    print(response.output_text)
    oidc-responses.sh
    curl --fail-with-body https://ai-gateway.vercel.sh/v1/responses \
      -H "Authorization: Bearer $VERCEL_OIDC_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
      "model": "anthropic/claude-sonnet-5",
      "input": "Why is the sky blue?"
    }'
Last updated September 8, 2026

Was this helpful?

supported.