Requesting more advanced models

This guide uses a more advanced model, GPT-4o. If you need help with API keys or environment configuration, go back to the previous step and follow the detailed quickstart guide for the free Gemma 3 model.


Making an API Call

circle-info

In the examples below, we use the OpenAI SDK. This is possible due to our compatibility with most OpenAI APIs, but this is just one approach. You can also use other supported SDKs, or call our API directly using cURL.

The chat model used in this example is more advanced. In addition to regular user messages, it supports the system role in the messages parameter, which can be used to define global instructions that affect the model’s overall behavior, for example:

messages: [
    {
      role: "system",
      content: "You are a travel agent. Be descriptive and helpful.",
    },
    {
      role: "user",
      content: "Tell me about San Francisco",
    },
],

Here’s the complete code you can use right away in a cURL, Python, or Node.js program. You only need to replace <YOUR_AIMLAPI_KEY> with your AIML API key from your account, provide your behavior instructions in the system prompt, and place your request to the model in the user prompt.

curl -L \
  --request POST \
  --url 'https://api.aimlapi.com/v1/chat/completions' \
  --header 'Authorization: Bearer <YOUR_AIMLAPI_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "system",
        "content": "You are a travel agent. Be descriptive and helpful.",
      }, 
      {
        "role": "user",
        "content": "Tell me about San Francisco"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 512
  }'

Future Steps

Last updated

Was this helpful?