# Messages APIs and Provider SDKs

> Make your first real calls to Claude, OpenAI and Gemini APIs and understand the shared shape: system prompt, message roles and response metadata. Free notes,...

Canonical: https://www.internhack.in/roadmaps/tracks/ai-engineer/first-api-calls
Last updated: 2026-11-28

Make your first real calls to Claude, OpenAI and Gemini APIs and understand the shared shape: system prompt, message roles and response metadata.

Beginner · about 5 hours · difficulty 2/5

Learn first: [HTTP, REST APIs and JSON](https://www.internhack.in/roadmaps/tracks/ai-engineer/http-apis-json), [Tokens and Context Windows](https://www.internhack.in/roadmaps/tracks/ai-engineer/tokens-and-context)

All major providers expose a similar chat-style interface: you send a list of **messages** with roles (system or developer instructions, user, assistant) and get back an assistant message plus metadata.

### The shared anatomy of a request

- **Model name**: read it from config; model versions change often.
- **System prompt**: persistent instructions and persona. Some APIs pass it as a separate field, others as a message with a special role.
- **Messages**: alternating user and assistant turns. The API is **stateless**; you resend the history each time (some providers offer server-side conversation state as an option).
- **Parameters**: max tokens, temperature, stop sequences.

### The response

- The generated content (often a list of content blocks: text, tool calls, images).
- A **stop reason** such as end of turn, max tokens reached, or tool use requested.
- **Usage**: input and output token counts. Log these on every call; they are your cost data.

### SDKs

Use the official SDKs (Anthropic, OpenAI, Google Gen AI) rather than raw HTTP; they handle retries, typing and streaming. Many providers and local servers also offer an **OpenAI-compatible endpoint**, which is handy but may not expose provider-specific features. Keep keys in environment variables and call models from your server, never directly from a browser.

### Good enough to move on

You can make a multi-turn conversation work with at least two providers, log token usage, and handle the max-tokens stop reason.

## Key concepts

- **Anthropic Claude API**
- **OpenAI API**
- **Google Gemini API**
- **System prompts and message roles**
- **Stateless multi-turn conversations**
- **Stop reasons and usage metadata**
- **OpenAI-compatible endpoints**
- **Cloud platforms (Bedrock, Vertex, Azure)**

## Mini project

Build a terminal chatbot that keeps multi-turn history, lets you switch between two providers with a flag, and prints token usage and estimated cost after every turn.

## Check yourself

If the API is stateless, how does a chatbot remember what the user said three turns ago, and what problem does this create for long chats?

## Free resources

- [Anthropic API documentation](https://docs.anthropic.com/) (Anthropic)
- [OpenAI platform documentation](https://platform.openai.com/docs) (OpenAI)
- [Gemini API documentation](https://ai.google.dev/gemini-api/docs) (Google)

Previous: [The Model Landscape and Choosing a Model](https://www.internhack.in/roadmaps/tracks/ai-engineer/choosing-models) · Next: [Streaming Responses](https://www.internhack.in/roadmaps/tracks/ai-engineer/streaming-responses)

## More in Working with Model APIs

- [Messages APIs and Provider SDKs](https://www.internhack.in/roadmaps/tracks/ai-engineer/first-api-calls)
- [Streaming Responses](https://www.internhack.in/roadmaps/tracks/ai-engineer/streaming-responses)
- [Structured Outputs and JSON Schema](https://www.internhack.in/roadmaps/tracks/ai-engineer/structured-outputs)
- [Tool and Function Calling](https://www.internhack.in/roadmaps/tracks/ai-engineer/tool-calling)
- [Prompt Caching and Batch Processing](https://www.internhack.in/roadmaps/tracks/ai-engineer/prompt-caching-batching)
- [Rate Limits, Errors and Cost Awareness](https://www.internhack.in/roadmaps/tracks/ai-engineer/rate-limits-and-cost)
- [Running Open-Weight Models Locally](https://www.internhack.in/roadmaps/tracks/ai-engineer/open-weight-models)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [AI Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/ai-engineer)
