> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keywordsai.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload image

> Learn how to upload image variables through Keywords AI gateway.

If you're using the Keywords AI gateway, you can upload images to the LLM request.

We support `base64` or `url` format for image variables.

## Upload image variables

<Tabs>
  <Tab title="OpenAI SDK">
    <CodeGroup>
      ```python OpenAI SDK Python {11-13} theme={"system"}
      from openai import OpenAI

      client = OpenAI(
          base_url="https://api.keywordsai.co/api/",
          api_key="YOUR_KEYWORDSAI_API_KEY",
      )

      response = client.chat.completions.create(
          model="gpt-4o-mini", # any model that supports image variables
          messages=[{"role":"user", "content":"Tell me a long story"}],
          extra_body={
              "variables": {
                  "image_variable": {"_type": "image_url", "value": "url_string"}
              }
          },  
      )
      ```

      ```javascript OpenAI SDK JavaScript {12-18} theme={"system"}
      import { OpenAI } from "openai";

      const client = new OpenAI({
        baseURL: "https://api.keywordsai.co/api/",
        apiKey: "YOUR_KEYWORDSAI_API_KEY",
      });

      const response = await client.chat.completions
        .create({
          messages: [{ role: "user", content: "Say this is a test" }],
          model: "gpt-4o-mini",
          // @ts-expect-error
          variables: {
            image_variable: {
              _type: "image_url",
              value: "url_string",
            },
          },
        })
        .asResponse();

      console.log(await response.json());
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Standard API">
    <CodeGroup>
      ```python Standard API Python {14-16} theme={"system"}
      import requests
      def demo_call(input, 
                    model="gpt-4o-mini", # also try "claude-3-5-sonnet-20240620"
                    token="YOUR_KEYWORDS_AI_API_KEY"
                    ):
          headers = {
              'Content-Type': 'application/json',
              'Authorization': f'Bearer {token}',
          }

          data = {
              'model': model,
              'messages': [{'role': 'user', 'content': input}],
              'variables': {
                  'image_variable': {'_type': 'image_url', 'value': 'url_string'}
              }
          }

          response = requests.post('https://api.keywordsai.co/api/chat/completions', headers=headers, json=data)
          return response

      messages = "Say 'Hello World'"
      print(demo_call(messages).json())
      ```

      ```javascript Standard API JavaScript {10-12} theme={"system"}
      fetch('https://api.keywordsai.co/api/chat/completions', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer YOUR_KEYWORDS_AI_API_KEY'
        },
          body: JSON.stringify({
              model: 'gpt-4o-mini', // also try "claude-3-5-sonnet-20240620"
              messages: [{role: 'user', content: "Say 'Hello World'"}],
              variables: {
                  'image_variable': {'_type': 'image_url', 'value': 'url_string'}
              }
          })
      })
      .then(response => response.json())
      .then(data => console.log(data));
      ```
    </CodeGroup>
  </Tab>
</Tabs>
